上一篇: Shell常见知识
ping发现掉包报警shell
[ 2009/04/20 16:22 | by selboo ]
#!/bin/bash
PING=`which ping`
DATE=`date +%Y%m%d%H%M`
TAIL=`which tail`
LOG=./ping$DATE.log
HOSTS="selboo.com.cn 221.130.191.97"
COUNT=200
for myHost in $HOSTS
do
count=$(ping -c $COUNT $myHost | grep ‘loss' | awk -F',' '{ print $3 }' | awk -F “%” ‘{ print $1 }')
if [ $count -ge 10 ]; then
/bin/echo selboo | mutt -s "$myHost pingispacketloss>10% $DATE" root@selboo.com.cn
fi
done
exit 0
复制上以上内容为ping.sh加入crontab中让其10分钟跑一次,其中发邮件程序为mutt
mutt命令参考以前的文章