Batch Check multiple Web site addresses are normal
Requirements: Shell array method Implementation, detection strategy as far as possible to simulate user access ideas
http://www.etiantian.org
Http://www.taobao.com
Http://oldboy.blog.51cto.com
http://10.0.0.7
Ideas:
1.url list as an array
2.check_url
3. Determine the output.
Answer:
The script is as follows:
[[email protected] oldboy26]# cat ms6.sh #!/bin/bash[ -f /etc/init.d/ functions ] && source /etc/init.d/functions#define array url Listarray= (http://www.etiantian.orghttp://www.taobao.comhttp://oldboy.blog.51cto.comhttp://10.0.0.7 ) # Check_urlwait () {echo -n "Wait 3s" for ((i=0;i<3;i++)) do echo -n "." sleep 1doneecho }check_url () { wget -t 5 -t 2 -- spider $1 &>/dev/null retval=$? if [ $RETVAL -eq 0 ];then action "Check $1" /bin/true else action "Check $1" /bin/false fi return $RETVAL}main () { wait for (i=0;i<${#array [@]};i+ +)) do cHeck_url ${array[i]} done}main verification: [[email protected] oldboy26]# sh ms6.sh wait 3s...check http://www.etiantian.org [ OK ]check http://www.taobao.com [ ok ]check http:// oldboy.blog.51cto.com [ ok ]check http ://10.0.0.7 [failed][[email protected] oldboy26]#
How to implement detect only one URL
[[Email protected] oldboy26]# cat ms6-01.sh#!/bin/bash[ -f /etc/init.d/functions ] && source /etc/init.d/functions#check_urlwait () {echo -n "wait 3s "For ((i=0;i<3;i++)) do echo -n ". " sleep 1doneecho }check_url () { wget -t 5 -t 2 -- spider $1 &>/dev/null retval=$? if [ $RETVAL -eq 0 ];then action "Check $1" /bin/true else action "Check $1" /bin/false fi return $RETVAL}main () { wait check_url $1 }main $* verification: [[email protected] oldboy26]# sh ms6-01.sh http:// oldboy.blog.51cto.comwait 3s...check http://oldboy.blog.51cto.com [ ok ][[email protected] oldboy26]# sh ms6-01.sh http://abc.134.comwait 3s...check http://abc.134.com [FAILED][[email protected] oldboy26]#
This article is from the "Zhou-linux Cultivation Road" blog, please be sure to keep this source http://zhouzefang.blog.51cto.com/9475331/1733387
Enterprise Shell Combat-Batch check multiple website address is normal