curl 监控web

[root@rhel6 ~]# curl -I -s -w "%{http_code}\n" -o /dev/null http://127.0.0.1
200
[root@rhel6 ~]# curl -I http://127.0.0.1 2>/dev/null | head -1 | egrep "200|300|301"
HTTP/1.1 200 OK

 

#!/bin/bash

if [ $# -ne 1 ];then
        echo $"Usage $0 url"
        exit 1
fi

while true;do
        res=`curl -o /dev/null --connect-timeout 2 -s -w "%{http_code}" $1|grep -E -w "200|301|302"|wc -l`
        if [ $res -ne 1 ];then
                echo "$1 is down."
        else
                echo "$1 is ok."
        fi
        sleep 10
done

 

posted @ 2018-02-24 13:54  Gringer  阅读(114)  评论(0)    收藏  举报