首页 > Web开发 > 详细

shell简单检查URL

时间:2021-05-16 14:27:20      阅读:10      评论:0      收藏:0      [点我收藏+]

#!/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

shell简单检查URL

原文:https://www.cnblogs.com/slyy/p/14773387.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!