#!/bin/sh

. /etc/init.d/functions

function checkURL()
{
    checkUrl=$1
    echo 'check url start ...'
    judge=($(curl -I -s --connect-timeout 2 ${checkUrl}|head -1|tr "\r" "\n"))
    if [ "${judge[1]}" == '200' -a "${judge[2]}" == 'OK' ]    #判断http状态码且字符为OK
        then
            action "${checkUrl}" /bin/true
        else
            action "${checkUrl}" /bin/false

            echo -n "retrying again...";sleep 3;

            judgeagain=($(curl -I -s --connect-timeout 2 ${checkUrl}|head -1|tr "\r" "\n"))
            if [ "${judgeagain[1]}" == '200' -a "${judgeagain[2]}"=='OK' ]
            then
                action "${checkUrl},retried again" /bin/true
            else
                action "${checkUrl},retried again" /bin/false
            fi
        fi
        sleep 1;
}
#usage method
checkURL www.baidu.com

相关文章:

  • 2021-07-19
  • 2021-09-12
  • 2022-01-20
  • 2021-05-31
  • 2021-06-01
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
猜你喜欢
  • 2022-12-23
  • 2021-06-30
  • 2021-08-05
  • 2021-06-09
  • 2021-04-14
  • 2021-07-24
  • 2022-12-23
相关资源
相似解决方案