09/24/13

shell脚本分享【监控链接访问情况】

#!/bin/sh
id=`curl -I –connect-timeout 20 http://blog.phpdba.com/post/110|awk ‘{ print $2;exit}’`
status=no
while [ true ]
do
sleep 10
if [ "${id}" != 200 ] && [ "$status" = ok ] ; then
echo ‘什么事都不做’
sleep 5
elif [ "${id}" != 200 ]; then
echo ‘发邮件通知’
echo ‘重启’
sleep 5
status=ok
elif [ "${id}" = 200 ] && [ "$status" = ok ]; then
echo ‘发邮件通知服务恢复’
sleep 5
status=no
elif [ "${id}" = 200 ]; then
echo ‘正常’
fi
id=`curl -I –connect-timeout 20 http://blog.phpdba.com/post/110|awk ‘{ print $2;exit}’`
done