Shell detects site status code and access time

Source: Internet
Author: User

[[Email protected] script]# cat test_site.sh #!/bin/bash    sites = ("http://10.0.0.2"   "http://www.163.com")  #  sites to monitor   notice_email= ' [email  Protected] '                                   #  Admin email   date=$ (date +%y-%m-%d '   '%h:%m:%s) function sendmail () {          echo $1         }function  check_site_code () {#  cycle to determine each site          for  site in ${sites[*]}; do                 printf  "start to access ${site}\n"                 site_code=$ (curl -o /dev/null -s -w %{http_code}  "${ Site} ")                 printf   "$ (date  ' +%y-%m-%d %h:%m:%s ') \ n"                printf  "site http code return:${site_code}\n\n"              if [ ${site_code} != 200 ];                 then                          echo  "Subject: ${site} can ' t access ${date}"  |  SENDMAIL ${NOTICE_EMAIL}               fidone}function mAx_access_time () {       for site in ${sites[*]}; do          site_access_time=$ (curl -o /dev/null -s  -w  "Time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total:  %{time_total} " " ${site} ")         echo  " $site "         time_total=${site_access_time##*:}            #echo   "$time _total"          printf  "site access time\n${time_total}\n"         var=$ {time_total%.*}                 if [ ${var} -ge 2 ];                         then                                  echo  "Subject: ${site} can ' t access ${date}  " | SENDMAIL ${NOTICE_EMAIL}                 fi       done}function send_mail () {         /usr/local/python}echo  "check the httpd  Code "check_site_codeecho "-----------------------------------------"\necho " check max  Access time "Max_access_time


This article is from "Zen Sword as" blog, please be sure to keep this source http://yanconggod.blog.51cto.com/1351649/1906247

Shell detects site status code and access time

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.