Enterprise Shell Combat-Batch check multiple website address is normal

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.