写一个监控网站的脚本。发现不正常发邮件告警。每分钟检测一次。
提示: 使用curl命令检测,根据结果判断。
#!/bin/bash
url=http://www.apelearn.com/bbs/forum.php
ip1=1.1.1.1
ip2=2.2.2.2
ip3=3.3.3.3
cop="--connect-timeout 3 -I"
check() {
curl $cop -x $1:80 $url 2>/dev/null > /tmp/curl.log
if [ $? != "0" ]
then
tag=1
else
code=`head -1 /tmp/curl.log |awk ‘{print $2}‘`
if [ $code == "200" ]
then
tag=0
else
tag=2
fi
fi
if [ $tag != "0" ]
then
echo "$1 wrong"|mail -s apelearn_$1
306798658@qq.com
2>/dev/null
fi
}
check $ip1
check $ip2
check $ip3本文出自 “Linux菜鸟” 博客,请务必保留此出处http://490617581.blog.51cto.com/11186315/1766495
原文地址:http://490617581.blog.51cto.com/11186315/1766495