檢查郵件伺服器的postfix-pop3-mysql服務狀態的指令碼

來源:互聯網
上載者:User

即時監控郵件伺服器的狀態需要指令碼任務做支撐

#!/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服務的檢查 存在則發郵件顯示正常,否則就重啟服務

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! will start!" >/tmp/pop_down;

mail -s  "pop3-down(IP-)" -c $mailer2  $mailer < /tmp/pop_down;

service  dovecot start;

fi

#postfix服務的檢查 存在則發郵件顯示正常,否則就重啟服務

postfix=`ps aux |grep postfix | grep -v "grep" |grep -v "root"| awk {'print $1'} | 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! will start!">/tmp/postfix_down;

mail -s "postfix-down(IP)" -c $mailer2 $mailer < /tmp/postfix_down;

service  postfix start;

fi

#Mysql 的狀態檢查,看是否存在mysql?存在則發郵件報告正常,否則就重啟服務

mysql=`ps aux |grep mysql |grep -v "grep" |awk {'print $1'} |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! will start!" > /tmp/mysql_down;

mail -s "mysql-down(IP)" -c $mailer2 $mailer < /tmp/mysql_down;

 service  mysqld start;

fi

返回欄目頁:http://www.bianceng.cnhttp://www.bianceng.cn/Servers/Mail/

將上述儲存成可執行檔檔案,添加cron計劃任務中,每10分鐘運行一次

本文出自 “影子騎士” 部落格,請務必保留此出處http://andylhz2009.blog.51cto.com/728703/494420

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.