ping主机不通邮件报警

#!/bin/bash
#Author: wang
#Date: 20170825

for ip in "192.168.101.28"
do
ping -c 1 $ip &>/dev/null #三个ping有一个能通,说明服务器正常
a=$?
sleep 2
ping -c 1 $ip &>/dev/null
b=$?
sleep 2
ping -c 1 $ip &>/dev/null
c=$?
sleep 2
DATE=$(date +%F" "%H:%M)
if [ $a -ne 0 -a $b -ne 0 -a $c -ne 0 ];then

/usr/local/bin/sendEmail -f [email protected] [email protected] -s smtp.163.com -u "Ping $ip online failed"
-o message-content-type=html -o message-charset=utf8 -xu [email protected] -xp 密码
-m "Date : $DATE\nHost : $ip\nProblem : Ping is failed." >> /opt/shell/crontab/ping.log

#else
# echo "$ip ping is successful."
fi
done

猜你喜欢

转载自www.cnblogs.com/donghui521/p/9728451.html