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