首页 > 代码库 > shell检测网站状态码和访问时间
shell检测网站状态码和访问时间
[root@hddcluster2 script]# cat test_site.sh #!/bin/bash SITES=("http://10.0.0.2" "http://www.163.com") # 要监控的网站 NOTICE_EMAIL=‘me@example.com‘ # 管理员电邮 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检测网站状态码和访问时间
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。