#!/bin/bash
sendmail() {
/usr/local/bin/sendEmail -f xyxsender@163.com -t test@relearn.com -s smtp.163.com -u "SERVER 192.168.31.$i" -xu xyxsender@163.com -xp "123456" -m "Alert: web 192.168.31.$i can‘t access"
}
while :
do
for i in {129,202,130}
do
status_code=`curl -I -o /dev/null -s -w "%{http_code}\n" http://192.168.31.$i`
if [ $status_code -ne 200 ]
then
sendmail
echo `date` >> /var/log/WebAlert.log
echo "Alert Email has been sent" >> /var/log/WebAlert.log
echo "---------------------------------------------"
fi
done
sleep 10
done
本文出自 “态度决定一切” 博客,请务必保留此出处http://relearn.blog.51cto.com/2605709/1693920
原文:http://relearn.blog.51cto.com/2605709/1693920