#!/bin/bash
# ping监控 , 发邮件
MAIL(){
#echo `date +'%Y-%m-%d %H:%M:%S'` >> /tmp/ping-error.txt
echo "$IP is error count is $count" |mail -s "ping $IP" 750657961@qq.com
}
PING(){
count=`/bin/ping -c 7 -W 3 $IP|grep "time="|egrep -v "DUP" |wc -l`
if (($count < 3));then
MAIL
else
#echo `date +'%Y-%m-%d %H:%M:%S'` >> /tmp/ping-ok.txt
echo "$IP is ok"
fi
}
IP_LIST="xx.xx.xx.xx yy.yy.yy.yy"
#多个ip轮询,监控并不实时
for IP in $IP_LIST;do
PING
done