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

 

 Options:

  -I/--head          Show document info only

  -s/--silent        Silent mode. Don't output anything

  -w/--write-out <format> What to output after completion

  -o/--output <file> Write output to <file> instead of stdout

  -k/--insecure    turn off curl's verification of the certificate

  --retry <num>   Retry request <num> times if transient problems occur

  --connect-timeout <seconds> Maximum time allowed for connection

posted @ 2017-03-17 18:04  Vincen_shen  阅读(574)  评论(0编辑  收藏  举报