|
利用wget监控某网站是否正常
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| #!/bin/bash
[ -f /etc/init.d/functions ] && . /etc/init.d/functions
USAGE(){
echo "$0 URL"
exit 0
}
check_web(){
wget --spider --timeout=100 --tries=2 $1 &>/dev/null
if [ $? -ne 0 ]
then
action "$1 already down" /bin/false
else
action "$1 is running" /bin/true
fi
}
main(){
if [ $# -ne 1 ]
then
USAGE
else
check_web $1
fi
}
main $*
|
利用curl监控某网站是否正常
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| #!/bin/bash
[ -f /etc/init.d/functions ] && . /etc/init.d/functions
USAGE(){
echo "$0 URL"
exit 0
}
check_web(){
HTTP_CODE=`curl -I -s -w "%{http_code}\n" -o /dev/null $1`
if [ $HTTP_CODE -eq 200 -o $HTTP_CODE -eq 301 ]
then
action "$1 is running" /bin/true
else
action "$1 already been down" /bin/false
fi
}
main(){
if [ $# -ne 1 ]
then
USAGE
else
check_web $1
fi
}
main $*
|
|
|
|
|
|
|
|