黑帽联盟

标题: 利用shell脚本判断网站访问是否正常-定位原创 [打印本页]

作者: 定位    时间: 2016-11-12 20:56
标题: 利用shell脚本判断网站访问是否正常-定位原创
利用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[1]}" == "200" -a "${judge[2]}" == "OK" ];then
#            echo "${judge[1]} ${judge[2]}"
            action "${address[$i]}" /bin/true
        else
#            echo "${judge[1]} ${judge[2]}"
            action "${address[$i]}" /bin/false
        fi
    done
}

check_url




效果图:

shell脚本程序







欢迎光临 黑帽联盟 (https://bbs.cnblackhat.com/) Powered by Discuz! X2.5