发现不正常发邮件告警。每分钟检测一次。提示: 使用curl命令检测,根据结果判断。
#!/bin/bash
url=http://www.apelearn.com
ip1=192.168.32.142
ip2=127.0.0.1
ip3=localhost
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 312903444@qq.com 2>/dev/null
fi
}
check $ip1
check $ip2
check $ip3