运维脚本---------批量判断网站是否能够访问正常

#获得访问状态码
#! /bin/bash
URL_LIST="baidu.com ali.com"
for URL in $URL_LIST;do
    FAIL_COUNT=0
    for ((i=1;i<=3;i++));do
        HTTP_CODE=$(curl -o /de/dev/null --connect-timeout 3 -s -w "%{http_code}" URL)
        if [ $HTTP_CODE -eq 200 ];then
        # echo "ok"
        break
         else
        echo "$URL retry $FAIL_COUNT"
        let FAIL_COUNT++
          fi
    done
    if [ $FAIL_COUNT -eq 3 ]; then
        echo "Waring: $URL Access failure!"
    fi
done

 

posted @ 2022-08-21 22:36  CiscoLee  阅读(124)  评论(0编辑  收藏  举报