#!/bin/bash# uses curl to check if the Web page can be accessed properly and to send the message if it is unreachable. Site=crm.bjzgjh.comprot=80url= "/http $SITE: $PROT" #mail_infoemail_sender = ([email protected] [email Protected]) email_title= "$SITE Port $prot fault WARNING!!! "Email_content=" host $site: $PROT do not pass! Please deal with it in time. \ n Monitor mail without replying "time=3check_once () {echo echo" $ (date) monitor check once "# 2018.03.09-i/-- Head-s/--silent #if curl-s-i--connect-timeout 5--max-time http://localhost:$1/; Then if Curl-s-i-l--connect-timeout 5--max-time $URL | Grep-q ' OK '; Then echo "$ (date) Web maybe OK" time=3 else echo "$ (date) Web maybe FAILURE "If [$time-gt 0];thennotify_error ((time = time-1)) Fiecho" $ (date) mail send ok "fi} #故障邮件报警notify_error ( {for var in ${email_sender[@]};d oecho--------------------------------------------echo-e ' date + '%y-%m-%d%h:%m.%s ' $email _content | /bin/mail-s $email _title $vardone}# Check that the webpage is normal while true at every minute; Do Sleep check_once >>/root/logs/check.$ (date +%y-%m-%d). Log Done
Reference Link: https://www.cnblogs.com/dim2046/p/5913701.html
Simple monitoring of website access is normal shell script, mail alarm. Continue running after the site resumes.