Check the site status usually using the wget or Curl tool, the following two tools are used to write the script to check the Web site. (Learning from the old boy shell programming)
Command line:
1. Curl gets a return value of 200, indicating normal
[Email protected] ~]# Curl-o/dev/null-s--connect-timeout 5-w '%{http_code} ' www.baidu.com 200[[email protected] ~] |
2, wget get 0, indicating normal
[Email protected] ~]# wget-t 5-t 2--spider www.baidu.com &>/dev/null [[email protected] ~]# echo $? 0 |
Script:
1, CULR
[email protected] shell]# cat check_web1.sh #!/bin/bash # [-f/etc/init.d/functions] &&. /etc/init.d/functions Array= ( http://www.china-cmd.org http://www.cmdmedia.cn Http://www.icehtmc.com https://mail.cmdmedia.cn ) Curl_ip () { curl=$ (Curl-o/dev/null-s--connect-timeout 5-w '%{http_code} ' $1|egrep "200|302" |wc-l) Return $CURL } Main () { For n in ${array[*]} Do Curl_ip $n If [$?-eq 1];then Action "Curl $n"/bin/true Else Action "Curl $n"/bin/false Sleep 3 curl=$ (curl_ip $n |egrep "200|302" |wc-l) If [$CURL-eq 1];then Action "Retry Curl $n Again"/bin/true Else Action "Retry Curl $n Again"/bin/false Fi Fi Done } Main |
Icon:
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/8D/BB/wKiom1ioYOWCw9-QAAFDKf159i8710.jpg "title=" Qq20170218225738.jpg "alt=" Wkiom1ioyowcw9-qaafdkf159i8710.jpg "/>
2, wget
[email protected] shell]# cat check_web2.sh #!/bin/bash # [-f/etc/init.d/functions] &&. /etc/init.d/functions Array= ( http://www.china-cmd.org http://www.cmdmedia.cn Http://www.icehtmc.com https://mail.cmdmedia.cn ) Curl_ip () { Wget-t 5-t 2--spider $ &>/dev/null Return $? } Main () { For n in ${array[*]} Do Curl_ip $n If [$?-eq 0];then Action "Curl $n"/bin/true Else Action "Curl $n"/bin/false Fi Done } Main |
Icon:
650) this.width=650; "src=" Https://s5.51cto.com/wyfs02/M00/8D/B9/wKioL1ioYWHxSX3dAAFI8IzODi8221.jpg "title=" Qq20170218225959.jpg "alt=" Wkiol1ioywhxsx3daafi8izodi8221.jpg "/>
Learn from:
Old boy Shell
This article is from the "Zhao Dongwei blog" blog, make sure to keep this source http://zhaodongwei.blog.51cto.com/4233742/1899145
Shell Script checks Site status