最近刚好需要测试一下新建站的稳定性,所以写了个shell脚本放到本机(最近换了mac本),能够实时查看你需要监控的web页面状态,并发送到指定邮箱.
这里赞一下os x自带有crontab计划任务,可以直接在本机测试脚本啦^_^
# vi check_web_alive.sh
# check network
net_alive=$(ping -c 5 8.8.8.8 |grep 'received'|awk 'begin {fs=","} {print $2}'|awk '{print $1}')
if [ $net_alive == 0 ]; then
echo "network is not active,please check your network configuration!"
exit 0
fi
# check url
for((i=0; i!=${#web_url[@]}; ++i))
{
alive=$(curl -o /dev/null -s -m 10 -connect-timeout 10 -w %{http_code} ${web_url[i]} |grep"000000")
if [ "$alive" == "000000" ]; then
echo "'${web_url[i]}' can not be open,please check!" | mail -s "website notification to ${web_url[i]}" yourname@example.com
echo "failed"
else
echo "'${web_url[i]}' is ok!"
fi
}
如对本文有疑问, 点击进行留言回复!!
网友评论