xuyaxiu 发表于 2018-8-27 08:50:32

shell脚本wget crul监控某网站是否正常

#!/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 $*


页: [1]
查看完整版本: shell脚本wget crul监控某网站是否正常