vim chkweb.sh#!/bin/bash # WEB=("www.hofan.cn" "ums.hofan.cn" "i.hofan.cn" "192.168.51.6") CHKLOOP=3 LOG=/var/log/chkweb.log checkrs() { #检测次数 local I=1 while [ $I -le $CHKLOOP ]; do if curl --connect-timeout 1 http://$1 &> /dev/null;then return 0 fi let I++ done return 1 } while :; do for I in ${WEB[*]};do # ${WEB[*]} 取所有WEB数组值 if checkrs $I;then echo "`date +‘%F %H:%M:%S‘`,$I is On-line." >> $LOG else echo "`date +‘%F %H:%M:%S‘`,$I is gone." >> $LOG fi done
时间: 2024-11-04 09:49:11