写一个监控网站的脚本

发现不正常发邮件告警。每分钟检测一次。提示: 使用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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值