注:执行需要安装有expect解释器
检查netscreen防火墙
shell+expect编写
shell代码如下,重复执行expect调用,list.txt文件为要检查的防火墙信息
其它设备检查也可做参考(应用于telnet)
savedate=$IFS
IFS=':'
filelog="`date +%Y-%m-%d`.log"
> $filelog
while read ipaddr username password
do
> "$ipaddr.log"
date +%Y-%m-%d >> "$ipaddr.log"
echo "$ipaddr" >> "$ipaddr.log"
expect getmessag.exp $ipaddr $username $password | tee -a "$ipaddr.log"
done < list.txt /*要检查的设备IP,用户名,密码列表
echo "***************************************************"
echo "now get the important message....."
IFS=':'
while read ipaddr username password
do
sed -n '1,2p' "$ipaddr.log" >> $filelog
grep "Average" "$ipaddr.log"| awk -F": " '{print $2}' >> $filelog
grep "^Memory:" "$ipaddr.log"| awk -F" " '{print $3,$5}' |awk -F"," '' >> $filelog
grep "^alloc" "$ipaddr.log"|awk -F" " '{print $2}' | awk -F"/" '{print $1}' >> $filelog
rm $ipaddr.log
done < list.txt
IFS=$savedate
expect程序代码如下
set timeout 4
set ipaddr [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
spawn telnet 132.108.19.1
expect "login:"
send "用户名/r"
expect "*: "
send "密码/r"
expect "*>"
send "telnet $ipaddr/r"
expect "login:"
send "$username/r"
expect "password:"
send "$password/r"
expect "*->"
send "get performance cpu/r"
expect "*->"
send "get memory/r"
expect "*->"
send "get session | include alloc/r"
expect "*->"
send "exit/r"
expect "*>"
send "exit/r"
expect eof
list.txt文件格式如下
192.168.10.6:用户名:密码
192.168.10.16:用户名:密码
192.168.10.60:用户名:密码
192.168.10.7:用户名:密码
192.168.10.9:用户名:密码
检查netscreen防火墙
shell+expect编写
shell代码如下,重复执行expect调用,list.txt文件为要检查的防火墙信息
其它设备检查也可做参考(应用于telnet)
savedate=$IFS
IFS=':'
filelog="`date +%Y-%m-%d`.log"
> $filelog
while read ipaddr username password
do
> "$ipaddr.log"
date +%Y-%m-%d >> "$ipaddr.log"
echo "$ipaddr" >> "$ipaddr.log"
expect getmessag.exp $ipaddr $username $password | tee -a "$ipaddr.log"
done < list.txt /*要检查的设备IP,用户名,密码列表
echo "***************************************************"
echo "now get the important message....."
IFS=':'
while read ipaddr username password
do
sed -n '1,2p' "$ipaddr.log" >> $filelog
grep "Average" "$ipaddr.log"| awk -F": " '{print $2}' >> $filelog
grep "^Memory:" "$ipaddr.log"| awk -F" " '{print $3,$5}' |awk -F"," '' >> $filelog
grep "^alloc" "$ipaddr.log"|awk -F" " '{print $2}' | awk -F"/" '{print $1}' >> $filelog
rm $ipaddr.log
done < list.txt
IFS=$savedate
expect程序代码如下
set timeout 4
set ipaddr [lindex $argv 0]
set username [lindex $argv 1]
set password [lindex $argv 2]
spawn telnet 132.108.19.1
expect "login:"
send "用户名/r"
expect "*: "
send "密码/r"
expect "*>"
send "telnet $ipaddr/r"
expect "login:"
send "$username/r"
expect "password:"
send "$password/r"
expect "*->"
send "get performance cpu/r"
expect "*->"
send "get memory/r"
expect "*->"
send "get session | include alloc/r"
expect "*->"
send "exit/r"
expect "*>"
send "exit/r"
expect eof
list.txt文件格式如下
192.168.10.6:用户名:密码
192.168.10.16:用户名:密码
192.168.10.60:用户名:密码
192.168.10.7:用户名:密码
192.168.10.9:用户名:密码