Apache监控脚本

By | 2013年7月13日
#!/bin/bash
URL=http://www.xxx.com/
curlit()
{
curl --connect-timeout 15 --max-time 20 --head --silent "$URL" | grep '200'
}

doit()
{
 if ! curlit; then
 sleep 20
 /usr/bin/killall -9 httpd > /dev/null
 sleep 2
 /etc/init.d/httpd start > /dev/null
 echo $(date) "Apache Restart" >> /var/log/httpd/apachemonitor.log
 printf "$(date)-C1 Httpd down and restarting!" | mail -s "C1 HTTPD Server Error!!!!!" 702018304@qq.com
 curl "http://vps.lijialong.name/fetion/tome/fetion.php?message=web服务重启中&passport=xxx"
 sleep 30
 if ! curlit; then
 echo $(date) "Failed! Now Reboot httpd!" >> /var/log/httpd/apachemonitor.log
 printf "$(date)-C1 Httpd down and restart failed!" | mail -s "C1 HTTPD Server Error!!!!!" 702018304@qq.com
 curl "http://vps.lijialong.name/fetion/tome/fetion.php?message=web服务重启失败&passport=xxx"
 fi
 sleep 180
 fi
}

sleep 300
while true; do
doit > /dev/null
sleep 10
done

参考:http://www.bootf.com/599.html

自己增加了发送邮件和发送手机短信的功能,发送手机短信功能,请查看我的其他文章。

发表评论

电子邮件地址不会被公开。 必填项已用*标注