利用wget监控某网站是否正常
#!/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监控某网站是否正常
#!/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 $*
时间: 2024-10-09 05:22:32