每5分钟监控web服务器状态

此脚本用于实时监控多个网站状态,记录运行时间和错误情况,并通过邮件通知管理员。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

# more monotor_www_bbs_webserver.sh
#!/bin/bash
site1=www.sdtest.com
site2=bbs208.sdtest.com
site3=bbs209.sdtest.com
site4=bbs210.sdtest.com
status=200
while :
do
logdate=$(date +%Y'-'%m'-'%d' '%H':'%M':'%S)
        for site in $site1 $site2 $site3 $site4;do
                status=`curl -s --head http://$site | awk '/HTTP/ {print $2}'`
                if [ "$status" == "200" ]
                        then
                                echo "$logdate $site is running."
                        else
                            echo "$logdate $site seems error and the  first stats still is $status"
                            status=`curl -s --head http://$site | awk '/HTTP/ {print $2}'`
                            if [ "$status" != "200" ]
                   then
                                           echo "$logdate $site seems error and the second stats still is $status"
                                           echo "$logdate $site seems error and the second stats still is $status" | mail -s "$site not running,please check " 186*****30@www.com.cn
                           fi
                fi
done
sleep 300
done

# nohup /monotor_www_bbs_webserver.sh &

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值