配置每天8点到21点(需要24小时待命的无视这个)每隔5分钟执行一次检测
/etc/crontab新增一条:
*/5 8-21 * * * root /usr/jobdir/job.sh
这里我使用了curl,也可以使用ping,curl需要到/usr/ports/ftp/curl下进行make安装
crontab中要注意path变量(系统能否找到curl? curl路径 /usr/local/bin ),用户权限等问题
-
[personball@freebsd ~]$ cd /usr/jobdir/
-
[personball@freebsd /usr/jobdir]$ ls
-
URL.list alive.sh job.sh
-
[personball@freebsd /usr/jobdir]$
job.sh
-
#!/bin/bash
-
#FileName: job.sh
-
#Author: personball
-
#Date: 2012-8-13
-
-
while read url
-
do
-
./alive.sh $url &
-
done
-
exit 0
alive.sh
-
#!/bin/bash
-
#FileName:alive.sh
-
#Author:personball
-
#Date:2012-8-13
-
-
if [ $# -ne 1 ]
-
then
-
echo "Usage:$0 URL"
-
exit 1
-
fi
-
-
url=$1
-
curl -I --connect-timeout 60 -m 60 $url >/tmp/alive.$$ 2>/dev/null #检测目标
-
if grep 'HTTP/1.1 200 OK' /tmp/alive.$$ &>/dev/null
-
then
-
echo $1" OK!" >>/var/log/alive.log
-
else
-
echo $1" Sick!">>/var/log/alive.log
-
#curl -I ''$1"_is_sick" &>/dev/null #短信报警
-
fi
-
exit 0
URL.list
阅读(5360) | 评论(0) | 转发(1) |