利用wget检测网页是否正常访问

#!/bin/bash

function CheckUrl() {
timeout=5
fails=0
success=0
while true
    do
        wget --timeout=5 --tries=1 https://www.google.com -q -O /dev/null
        #use wget to CheckUrl can be used 
        if [ $? -ne 0 ]
            then
                let fails=fails+1
        else
                let success=success+1
        fi
        if [ $success -gt 1 ];then
            echo "Success"
            exit 0
        fi
        if [ $fails -gt 0 ];then
            echo "Failed"
            exit 1
        fi
    done
}
CheckUrl
posted @ 2017-05-16 16:49  午夜爬虫  阅读(2202)  评论(0编辑  收藏  举报