Script to check the Postfix-pop3-mysql service status of the mail server

Source: Internet
Author: User
Tags mail mysql dovecot

Real-time monitoring of mail server status requires scripting tasks to support

#!/bin/bash

#Purpose: Check Postfix and Pop3 MySQL service status

#Author: Andylhz

#Date: 2010-07-29

dt= ' Date ' +%y:%m:%d:%h:%m '

mailer=root@test.cn

Mailer2=138xxxxxxxx@139.com

host=mail.test.cn

#Dovecot服务的检查 exists, the message appears normal, otherwise the service will be restarted

dovecot= ' ps aux |grep pop3-login | Grep-v "grep" |awk {' Print $11 '} | Uniq '

If ["$dovecot" = = "Pop3-login"]; Then

echo "$dt < $host > POP3 service is ok!" >/tmp/pop_ok;

Mail-s "Pop3-ok (IP-154)" $mailer </TMP/POP_OK;

Else

echo "$dt < $host > POP3 Service is down! Would start! ">/tmp/pop_down;

Mail-s "Pop3-down (ip-)"-C $mailer 2 $mailer </tmp/pop_down;

Service Dovecot start;

Fi

#postfix服务的检查 exists, the message appears normal, otherwise the service will be restarted

postfix= ' ps aux |grep postfix | Grep-v "grep" |grep-v "root" | awk {' Print '} | Uniq '

If ["$postfix" = = "Postfix"]; Then

echo "$dt < $host > postfix service is ok!" >/tmp/postfix_ok;

Mail-s "Postfix-ok (IP)" $mailer </TMP/POSTFIX_OK;

Else

echo "$dt < $host > postfix service is down! Would start! " >/tmp/postfix_down;

Mail-s "Postfix-down (IP)"-C $mailer 2 $mailer </tmp/postfix_down;

service postfix start;

Fi

#Mysql status Check to see if Mysql exists? exists, the email report is normal, otherwise the service will be restarted.

Mysql= ' PS aux |grep mysql |grep-v "grep" |awk {' print '} |grep MySQL '

If ["$mysql" = "MySQL"]; Then

echo "$dt < $host > mysql is ok!" >/tmp/mysql_ok;

Mail-s "Mysql-ok (IP)" $mailer </TMP/MYSQL_OK;

Else

echo "$dt < $host > mysql is down! Would start! ">/tmp/mysql_down;

Mail-s "Mysql-down (IP)"-C $mailer 2 $mailer </tmp/mysql_down;

Service mysqld start;

Fi

Back to the column page: http://www.bianceng.cnhttp://www.bianceng.cn/Servers/Mail/

Save this as an executable file, add a cron scheduled task, run every 10 minutes

This article is from the "Shadow Knight" blog, please be sure to keep this source http://andylhz2009.blog.51cto.com/728703/494420

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.