Loading

08 批量检查网站是否异常

#!/bin/bash
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

URL_LIST=$1
for URL in $URL_LIST; do
    FAIL_COUNT=0
    for ((i=1; i<=3; i++)); do
        HTTP_CODE=$(curl -o /dev/null --connect-timeout 3 -s -w "%{http_code}\n" $URL | egrep -o "200|301|302|" | wc -l)
        if [ $HTTP_CODE -eq 1 ]; then
            echo "$URL OK"
            break
        else
            echo "$URL retry $FAIL_COUNT"
            let FAIL_COUNT++
        fi
    done
    if [ $FAIL_COUNT -eq 3 ]; then
        echo "Warning: $URL Access failure!"
    fi
done

 

posted @ 2021-04-24 20:13  云起时。  阅读(90)  评论(0编辑  收藏  举报