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 wangdonghui@163.com wangdonghui@wang.com -s smtp.163.com -u "Ping $ip online failed"
-o message-content-type=html -o message-charset=utf8 -xu wangdonghui@163.com -xp 密码
-m "Date : $DATE\nHost : $ip\nProblem : Ping is failed." >> /opt/shell/crontab/ping.log
#else
# echo "$ip ping is successful."
fi
done
曾经在幽幽暗暗反反复复中追问 才知道平平淡淡从从容容才是真