分类:
2008-06-10 20:26:21
学习并使用EXPECT后,AIX日常检查工作可实现自动化——从一个单点检查全局。每早8:00单点(某LPAR)用crontab触发一个任务,检查所有LPAR,然后将结果汇总并发送系统管理员的邮箱内。
下面是某天的检查结果内容(IP地址等信息被修改过):
>-----Original Message-----
> 发件人:
> 日期: Thu, 5 Jun 2008 08:02:17 +0800
> 收件人:
> 主题: AIX DAILY CHECK 08-06-05 08:01
> 31 out of 31 LPARs have been checked.
>
> ST-WMDB is 9.1.173.234
> Jun 05 9.1.173.241 pts dailyck
>
> ST-WMP is 9.1.173.233
> Jun 05 9.1.173.241 pts dailyck
> Jun 04 99.1.99.236 pts root
> Jun 04 99.1.99.236 ftp root
> Jun 04 9.1.173.241 pts dailyck
> Jun 04 9.1.170.94 pts root
>
> UAT-FTP is 9.1.172.230
> F89FB899 0604150008 P O dumpcheck The copy directory is too small.
> 97% /usr
> Jun 05 9.1.172.241 pts dailyck
> Jun 04 9.1.172.241 pts dailyck
>
> ST-FREE is 9.1.173.246
> F89FB899 0604150008 P O dumpcheck The copy directory is too small.
> 88% /opt
> Missing hdisk0 vscsi0
> Missing hdisk0 vscsi1
> Missing hdisk1 vscsi0
> Missing hdisk1 vscsi1
> Missing hdisk2 vscsi0
> Missing hdisk2 vscsi1
> Missing hdisk3 vscsi0
> Missing hdisk3 vscsi1
> Jun 05 9.1.173.241 pts dailyck
> Jun 04 9.1.173.241 pts dailyck
> Jun 04 9.1.170.99 pts chengjy
> Jun 04 9.1.170.99 ftp chengjy
> Jun 04 9.1.170.94 pts root
>
> ST-BIFE is 9.1.173.243
> F89FB899 0604150008 P O dumpcheck The copy directory is too small.
> 98% /usr
> 88% /opt
> 91% /db2space
> Jun 05 9.1.173.241 pts dailyck
> Jun 04 9.1.173.241 pts dailyck
>
> ST-MBFE1 is 9.1.173.235
> Jun 05 9.1.173.241 pts dailyck
>
> UAT-MBFE1 is 9.1.172.235
> 89% /usr
> Jun 05 9.1.172.241 pts dailyck
> Jun 04 9.1.172.241 pts dailyck
> Jun 04 9.1.170.94 pts root
>
> UAT-MBFE2 is 9.1.172.236
> 89% /usr
> Jun 05 9.1.172.241 pts dailyck
> Jun 04 9.1.172.98 pts cmbmbfe
> Jun 04 9.1.172.241 pts dailyck
>
> ST-MBFE3 is 9.1.173.237
> 89% /usr
> Jun 05 9.1.173.241 pts dailyck
> Jun 04 9.1.173.241 pts dailyck
>
> ST-MBFE2 is 9.1.173.236
> 99% /home/cmbmbfe
> Jun 05 9.1.173.241 pts dailyck
> Jun 04 9.1.173.241 pts dailyck
>
> UAT-DW is 9.1.172.244
> F89FB899 0604150008 P O dumpcheck The copy directory is too small.
> 98% /usr
> 88% /opt
> 91% /db2space
> Jun 05 9.1.172.241 pts dailyck
> Jun 04 9.1.172.241 pts dailyck
>
> ST-CRM is 9.1.173.242
> F89FB899 0604150008 P O dumpcheck The copy directory is too small.
> 98% /usr
> 88% /opt
> 91% /db2space
> Jun 05 9.1.173.241 pts dailyck
> Jun 04 9.1.173.241 pts dailyck
>
> ST-DW is 9.1.173.244
> F89FB899 0604150008 P O dumpcheck The copy directory is too small.
> 93% /var
> Jun 05 9.1.173.241 pts dailyck
> Jun 04 ST-DW rsh db2inst1
> Jun 04 99.1.99.62 pts dwadm
> Jun 04 99.1.99.62 pts db2inst1
> Jun 04 99.1.99.62 ftp dwadm
> Jun 04 99.1.99.236 pts wmsadm
> Jun 04 99.1.99.236 ftp wmsadm
> Jun 04 99.1.99.228 pts dwadm
> Jun 04 99.1.99.19 ftp dwadm
> Jun 04 9.1.173.241 pts dailyck
> Jun 04 9.1.170.94 pts root
> Jun 04 99.1.64.134 pts db2inst1
>
> VIOS2 is 9.1.172.241
> Jun 05 VIOS2 pts dailyck
> Jun 04 VIOS2 pts dailyck
> Jun 04 9.1.170.94 pts padmin
>
> VIOS1 is 9.1.172.240
> Jun 05 9.1.172.241 pts dailyck
> Jun 04 9.1.172.241 pts dailyck
> Jun 04 9.1.170.94 pts padmin
>
> svt6k01 is 9.1.172.70
> 97% /usr
> 94% /home/cbank
> Jun 05 9.1.172.241 pts dailyck
> Jun 04 9.1.172.99 pts qsmsadm
> Jun 04 9.1.172.63 pts qsmsadm
> Jun 04 9.1.172.61 pts qatm
> Jun 04 9.1.172.241 pts dailyck
> Jun 04 9.1.170.94 pts root
> Jun 04 9.1.170.78 pts root
> Jun 04 99.1.64.183 pts qatm
>
> UAT-WMDB is 9.1.172.234
> Jun 05 9.1.172.241 pts dailyck
>
> UAT-NI is 9.1.172.74
> 97% /usr
> 90% /db2home
> 91% /soft
> Jun 05 9.1.172.241 pts dailyck
>
> ST-WMP is 9.1.172.233
> Jun 05 9.1.172.241 pts dailyck
> Jun 04 9.1.172.241 pts dailyck
>
> UAT-MBFE3 is 9.1.172.237
> F89FB899 0604150008 P O dumpcheck The copy directory is too small.
> 87% /usr
> 87% /opt
> Jun 05 9.1.172.241 pts dailyck
> Jun 04 9.1.172.98 pts cmbmbfe
> Jun 04 9.1.172.241 pts dailyck
>
> UAT-STOCK is 9.1.172.71
> Jun 05 9.1.172.241 pts dailyck
>
> svt6k01 is 9.1.173.70
> 89% /home/cbank
> Jun 05 9.1.173.241 pts dailyck
> Jun 04 9.1.173.241 pts dailyck
>
> TEST is 9.1.173.249
> F89FB899 0603150008 P O dumpcheck The copy directory is too small.
> Jun 05 9.1.173.241 pts dailyck
>
> ST-STOCK is 9.1.173.71
> 86% /home
> Jun 05 9.1.173.241 pts dailyck
>
> NIMMASTER is 9.1.173.231
> F89FB899 0603150008 P O dumpcheck The copy directory is too small.
> 97% /usr
> 88% /opt
> 93% /export/spot
> Jun 05 9.1.173.71 ftp zbackup
> Jun 05 9.1.173.70 ftp zbackup
> Jun 05 9.1.173.241 pts dailyck
> Jun 05 9.1.172.71 ftp zbackup
> Jun 05 9.1.172.70 ftp zbackup
>
> VIOS3 is 9.1.172.242
> Jun 05 9.1.172.241 pts dailyck
>
> VIOS4 is 9.1.172.243
> Jun 05 9.1.172.241 pts dailyck
>
> ST-GANGLIA is 9.1.173.230
> F89FB899 0604150008 P O dumpcheck The copy directory is too small.
> 98% /usr
> 88% /opt
> Jun 05 9.1.173.241 pts dailyck
> Jun 04 9.1.173.241 pts dailyck
>
> ST-TAX is 9.1.173.232
> Jun 05 9.1.173.241 pts dailyck
> Jun 04 QMYJH ftp taxtst
> Jun 04 QMA001_DEV ftp taxtst
> Jun 04 99.1.99.194 pts db2inst1
> Jun 04 99.1.99.150 pts taxtst
> Jun 04 9.1.173.241 pts dailyck
> Jun 04 9.1.170.62 pts taxtst
> Jun 04 9.1.170.62 pts db2inst1
>
> UAT-TAX is 9.1.172.232
> Jun 05 9.1.172.241 pts dailyck
> Jun 04 9.1.172.241 pts dailyck
>
检查的内容目前包括(根据需要可随时调整):
每LPAR昨日开始的errpt错误日志
是否有使用率超过85%的文件系统
磁盘多路径IO状态是否有异常
昨日至今都有哪些用户、IP登录过本LPAR。
cat <<'!!' > /bin/dailyck.exp
#!/usr/bin/expect -f
#DATE: 2008-06-03
#email:
#blog: http://blog.chinaunix.net/index.php?blogId=739 http://www.cublog.cn/u/739/
set timeout 10
set username dailyck
set passwd 此处需要改成真密码
set logname /home/padmin/dailyck.log
match_max 10000
log_user 0
spawn telnet [lindex $argv 0]
expect "ogin:"
sleep .1
send -- "$username\r"
expect "assword:"
sleep .1
send -- "$passwd\r"
sleep .1
log_file $logname
expect {
""
{send -- "export PS1=$\r"}
"#"
{send -- "export PS1=$\r"}
"invalid login name or password"
{send_log "\n\n[lindex $argv 0] The password is wrong\n\n"; exit 1}
timeout
{send_log "\n\n[lindex $argv 0] Timeout\n\n"; exit 2}
eof
{send_log "\n\n[lindex $argv 0] Connection to host failed: expect_out(buffer)\n\n"; exit 3}
}
log_user 1
expect -exact "\r
\$"
send -- "ksh <<'!!!'\r"
send -- "echo \""
send -- "host `hostname`\r"
send -- "TODAY=`date +\"%m%d\"`\r"
send -- "YESTERDAY=`TZ=+24 date +\"%m%d\"`\r"
send -- "errpt | awk '\$2 ~ YESTERDAY\"......\" || \$2 ~ TODAY\"......\"' YESTERDAY=\$YESTERDAY TODAY=\$TODAY | grep -v 'T S SYSXDLCI'\r"
send -- "df | awk 'NR>1, sub(/%/,\"\",\$4){if ( \$4 > 85 ) print \$4\"%\\t\"\$NF}'\r"
send -- "lspath | grep -v ^Enabled\r"
#send -- "today=`date | awk '{print \$2\" \"\$3 \" |\"\$2\" 0\"\$3\" \"}'`\r"
#send -- "yestoday=`TZ=+24 date | awk '{print \$2\" \"\$3\" |\"\$2\" 0\"\$3\" \"}'`\r"
#send -- "eval last \\| egrep \"'(\$yestoday|\$today)'\" | "
#send -- "awk 'BEGIN{OFS=\""} NF==9 {sub(/\\/.*/,\"\",\$2); print \$4,\$5,\$3,\$2,\$1}; NF<9 {print}' | sort -r | uniq\r"
send -- "today=`date +\"%b %d\"`\r"
send -- "yestoday=`TZ=+24 date +\"%b %d\"`\r"
send -- "last | awk 'BEGIN {today='\\\"\"\$today\"; yestoday='\\\"\"\$yestoday\"} "
send -- "\$0 !~ today && \$0 !~ yestoday {exit}; NF==9 {sub(/\\/.*/,\"\",\$2); sub(/rsh.*/,\"rsh\",\$2); "
send -- "print \$4,\$5,\$3,\$2,\$1}; NF<9 {print}' | sort -r | uniq -c &&\r"
send -- "echo \""
send -- "!!!\r"
expect -exact "\r
\$"
log_file
send -- "exit\r"
interact
!!
chmod +x /bin/dailyck.exp
cat <<'!!' > /bin/dailyck.ksh
#!/usr/bin/ksh
#DATE: 2008-06-03
#email:
#blog: http://blog.chinaunix.net/index.php?blogId=739 http://www.cublog.cn/u/739/
]
]
LOG=/home/padmin/dailyck.log
LOGCOUNT=/home/padmin/dailyck.count
MAILFILE=/home/padmin/dailyck.mail
> $LOG
> $LOGCOUNT
#9.1.173.247 9.1.8.51 VIOS12
#9.1.172.50 LPAR ID 1 VIOS12
for i in `ssh "lspartition -dlpar" | awk -F[\ \>] '/99.1/ {print $(NF-1)}'|egrep -v '(73.247|72.50)'`; do
/usr/bin/dailyck.exp $i
echo $i $? >> $LOGCOUNT
done
for i in `ssh "lspartition -dlpar" | awk -F[\ \>] '/99.1/ {print $(NF-1)}'`; do
/usr/bin/dailyck.exp $i
echo $i $? >> $LOGCOUNT
done
echo `awk '$2==0' $LOGCOUNT | wc -l`" out of "`cat $LOGCOUNT | wc -l`" LPARs have been checked.\n" >$MAILFILE
awk '$2!=0' $LOGCOUNT >>$MAILFILE
tr -d "\015" <$LOG | grep -p 9.1 >>$MAILFILE
cat $MAILFILE | mail -s "AIX DAILY CHECK `date +'%y-%m-%d %H:%M'`" -c "$CC" $SENDTO
!!
chmod +x /bin/dailyck.ksh
========================================================================
任何形式的转载,请写明出处:
email:
blog: http://blog.chinaunix.net/index.php?blogId=739 http://www.cublog.cn/u/739/
========================================================================
chinaunix网友2008-10-02 23:24:14
来自123.116.149.★的兄弟,我大概猜到,您的意思是指中间位置的那堆send写得太难看,“\”太多了。不过那些是autoexpect自动生成的,我只是简单修改了下,就照搬过来的。我觉得这样做,工作效率最高,所以就顾不上美观了;而且我觉得再怎么美化,“\”的数量也无法接近零,所以索性就照搬autoexpect算了。不知兄弟有何高见?请不吝赐教!