shell检测网站状态码和访问时间
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell检测网站状态码和访问时间相关的知识,希望对你有一定的参考价值。
[[email protected] script]# cat test_site.sh #!/bin/bash SITES=("http://10.0.0.2" "http://www.163.com") # 要监控的网站 NOTICE_EMAIL=‘[email protected]‘ # 管理员电邮 DATE=$(date +%Y-%m-%d‘ ‘%H:%M:%S) function SENDMAIL() { echo $1 } function CHECK_SITE_CODE() { # 循环判断每个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} fi done } 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_CODE echo "-----------------------------------------"\n echo "check max access time" MAX_ACCESS_TIME
本文出自 “禅剑一如” 博客,请务必保留此出处http://yanconggod.blog.51cto.com/1351649/1906247
以上是关于shell检测网站状态码和访问时间的主要内容,如果未能解决你的问题,请参考以下文章