Simple Service port detection and alarm

Source: Internet
Author: User

1. Configure smtp information for the server

vim /etc/mail.rcset from=XXX@XXX.com smtp=smtp.xxx.com smtp-auth-user=XXX@XXX.com smtp-auth-password=xxxxx smtp-auth=login

Ii. service_check.sh check script content

#!/bin/bashfor port in 80 3306 10050 10022; doif `netstat -tnlp |grep $port &> /dev/null` ; then   if `tail -4 /root/lee/service_status.log |grep "$port failed" &> /dev/null` ;thenecho "`date +%F-%H:%M:%S` [`hostname`] `/sbin/ifconfig eth0 |grep "inet addr" |awk '{split($2,a,":"); print a[2]}'` [$port recovery]"> /root/lee/mail_content.txtmail -s "$port recovery" XXXXXXXXXX@139.com < /root/lee/mail_content.txt   fiecho "`date +%F-%H:%M:%S` $port no problem" >> /root/lee/service_status.logelseecho "`date +%F-%H:%M:%S` $port failed................"  >> /root/lee/service_status.logecho "`date +%F-%H:%M:%S` [`hostname`] `/sbin/ifconfig eth0 |grep "inet addr" |awk '{split($2,a,":"); print a[2]}'` [$port down]"> /root/lee/mail_content.txtmail -s "$port failed" XXXXXXXXXXXX@139.com < /root/lee/mail_content.txtfidone

Alarm Mechanism Description: If the port does not exist, a message is sent. After the port returns to normal, a recovery message is sent for confirmation.


3. Add scheduled tasks

*/5 * * * *  sh /root/lee/service_check.sh

Iv. Test

Manually disable the mysqld service

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131227/23460433K-0.png "title =" image 001.png" alt = "152020.8.png"/>

You will receive a text message or text message later.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131227/234604O20-1.png "title =" IMG_0756.PNG "alt =" 152114954.png"/>

Manually enable the mysqld service

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131227/234604L25-2.png "title =" image 002.png" alt = "152144989.png"/>

There will be a recovery receipt in 5 minutes

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131227/23460423a-3.png "title =" IMG_0757.PNG "alt =" 152229295.png"/>


5. The script content is already included in the attachment. You can test it by yourself.




This article from the "Sun Xiang" blog, please be sure to keep this source http://leezqang.blog.51cto.com/1525874/1301577

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.