定位 发表于 2016-11-12 20:56:55

利用shell脚本判断网站访问是否正常-定位原创

利用shell脚本判断网站访问是否正常,以下是个人写的脚本



#!/bin/bash

#auth:created by wanghao
#email:1074189538@qq.com
#func:judge url address ok or failed

. /etc/init.d/functions

address=(
https://bbs.cnblackhat.com
http://www.cnblackhat.com
http://192.168.43.234
)

function Wait() {
    echo -n '3秒后,执行该操作'
    for((i=0;i<3;i++))
do
    echo -n ".";sleep 1
done
    echo
}

function check_url() {
    Wait
    echo 'check url...'
    for((i=0;i<${#address[@]};i++))
    do
    judge=($(curl -I -s --connect-timeout 2 ${address[$i]}|head -1|tr "\r" "\n"))

        if [ "${judge}" == "200" -a "${judge}" == "OK" ];then
#            echo "${judge} ${judge}"
            action "${address[$i]}" /bin/true
        else
#            echo "${judge} ${judge}"
            action "${address[$i]}" /bin/false
        fi
    done
}

check_url




效果图:




页: [1]
查看完整版本: 利用shell脚本判断网站访问是否正常-定位原创