[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

相关文章:

  • 2022-01-11
  • 2021-07-16
  • 2022-12-23
  • 2021-07-14
  • 2021-09-10
  • 2021-07-30
  • 2022-01-14
猜你喜欢
  • 2022-12-23
  • 2021-05-29
  • 2021-05-12
  • 2021-07-21
  • 2021-10-14
  • 2021-07-26
  • 2021-04-27
相关资源
相似解决方案