The shell monitors the site for unusual script, such as an abnormal automatic email notification to the administrator.
Process:
1. Check that the Http_code returned by the Web site is equal to 200, if not 200 as an exception.
2. Check Web site access time, more than Maxloadtime (10 seconds) as an exception.
3. Send notification email, in the/tmp/monitor_load.remark record send time, in an hour does not repeat, such as an hour after the empty/tmp/monitor_load.remark.
#!/bin/bash sites= ("http://web01.example.com" "http://web02.example.com") # to monitor the site notice_email= ' me@example.co M ' # Admin Email maxloadtime=10 # access Timeout set RE Markfile= '/tmp/monitor_load.remark ' # has sent a notification email if it has been sent and will not be sent within an hour issend=0 # do you send email expire=3600 # Number of seconds to send email NO w=$ (date +%s) if [-F "$REMARKFILE"] && [-S "$REMARKFILE"]; Then remark=$ (cat $REMARKFILE) # Delete expired email delivery time record file if [$ ($NOW-$REMARK))-gt "$EXPIRE"]; Then rm-f ${remarkfile} remark= "fi else Remark=" "fi # Loops to judge each site for Si Te in ${sites[*]}; Do printf "start to load ${site}\n" site_load_time=$ (Curl-o/dev/null-s-W "Time_connect:%{time_conn Ect}\ntime_starttransfer:%{time_starttransfer}\ntime_total:%{time_total} "${site}" site_access=$ (Curl-o/dev/null-s-W%{http_code} "${site}") Time_tot al=${site_load_time##*:} printf "$ (date ' +%y-%m-%d%h:%m:%s ') \ n" printf "Site load Time\n${site_load_ti me}\n "printf" site access:${site_access}\n\n "# not send if [' $REMARK ' = ']; Then # check access if ["$time _total" = "0.000"] | | ["$site _access"!= "200"]; Then echo "Subject: ${site} can access $ (date +%y-%m-%d '%h:%m:%s)" | SendMail ${notice_email} issend=1 Else # Check load time if [' ${time_ total%%.*} "-ge ${maxloadtime}]; Then echo "Subject: ${site} load Time Total:${time_total} $ (Date +%y-%m-%d ' '%h:%m:%s ')" | SendMail ${notice_email} issend=1 fi fi done # send email PostScript Record sending time if ["$ISSEND" = "1"]; Then echo "$ (date +%s)" > $REMARKFILE fi exit 0
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/Servers/web/