您的位置:首页 > 运维架构 > Shell

shell脚本wget crul监控某网站是否正常

2016-11-23 22:42 417 查看
利用wget监控某网站是否正常
#!/bin/bash

[ -f /etc/init.d/functions ] && . /etc/init.d/functions
USAGE(){
echo "$0 URL"
exit 0
}
check_web(){
wget --spider --timeout=100 --tries=2 $1 &>/dev/null
if [ $? -ne 0 ]
then
action "$1 already down" /bin/false
else
action "$1 is running" /bin/true
fi
}
main(){
if [ $# -ne 1 ]
then
USAGE
else
check_web $1
fi
}
main $*


利用curl监控某网站是否正常
#!/bin/bash
[ -f /etc/init.d/functions ] && . /etc/init.d/functions
USAGE(){
echo "$0 URL"
exit 0
}
check_web(){
HTTP_CODE=`curl -I -s -w "%{http_code}\n" -o /dev/null $1`
if [ $HTTP_CODE -eq 200 -o $HTTP_CODE -eq 301 ]
then
action "$1 is running" /bin/true
else
action "$1 already been down" /bin/false
fi
}
main(){
if [ $# -ne 1 ]
then
USAGE
else
check_web $1
fi
}
main $*
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  shell wget curl