Monitor whether the running service is normal and send an email alert

Source: Internet
Author: User

Monitor whether the running service is normal and send an email alert

Monitoring Service, which is a task placed on crontab. I do not like to run it in the background using an endless loop.

Therefore, three cycles are executed each time. If any of the services is down, an alarm is triggered.

The effect of the three rewrite methods is the same.

#! /Bin/bash


Nmap-p 6065 10.31.6.6 | egrep "6065/tcp open" &>/dev/null
Code1 = $?

Nmap-p 80 10.31.6.6 | grep "80/tcp open http">/dev/null 2> & 1
Code2 = $?

Curl http: // 10.31.6.6/test.html/> &/dev/null
Code3 = $?



My_mail (){

Mail_list = ("test@hotmail.com.cn" "test2@hotmail.com.cn ")
Now_date = 'date "+ % Y-% m-% d % T "'
For I in $ {mail_list [@]}
Do
Echo-e "webchat is down, please check; \ nip: 42.62.5.100 \ n $ now_date" | mail-s "webchat down" $ I
Done
}



N = 1
Count = 1
While (n <4 ))
Do

If [$ code1 = 0] & [$ code2 = 0] & [$ code3 = 0]
Then
N = $ ($ n + 1 ))
Sleep 2

Else
Count = $ ($ count + 1 ))
N = $ ($ n + 1 ))
Sleep 2
If [$ count-eq 3]; then
My_mail
Fi

Fi

Done

This article permanently updates the link address:

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.