OpenVZ Forum


Home » General » Support » Script to Monitor Email Queue in the Container
Script to Monitor Email Queue in the Container [message #51827] Mon, 12 January 2015 11:43
hostingraja is currently offline  hostingraja
Messages: 5
Registered: January 2015
Location: Bangalore
Junior Member
From: *acttv.in
I have a written a small script to monitor and sends email alert when there is a lots of Email in the Queue.
Hope, helps someone.

#!/bin/bash
echo " " ;
echo "=======================================================================================================" ;
date ;
for i in `cat /proc/vz/veinfo | awk '{print $1}'|egrep -v '^0$'`;
do
    vmname=`/usr/sbin/vzctl exec2 $i hostname`
    printf "$vmname " ;
    #Check Exim MailQ
    emailcnt=0
    emailcnt=`/usr/sbin/vzctl exec2 $i /usr/sbin/exim -bpc 2> /tmp/emailcnt.log`
    if [ $? -eq 0 ]
    then
        : # do nothing
    else
        echo "the return value is $?"
        #Check Postfix MailQ
        emailcnt=`/usr/sbin/vzctll exec2 $i /usr/sbin/postqueue -p > /tmp/emailcnt.log 2> /dev/null`
        string=`cat /tmp/emailcnt.log`
        if [[ $string == *"empty"* ]]; then emailcnt=1 ; fi
    fi

    echo "Email Count $emailcnt" ;

    emailalert="yourmaailid here @gmail.com"
    if [[ "$emailcnt" -ge 50 ]]
    then
        echo "Sending mail now" ;
        echo -e "Email count on the Queue is $emailcnt : $vmname" | mail -s "Output of $0 on `hostname`" $emailalert
    fi

done


Nothing...
Previous Topic: Need help with script to take back up & restore
Next Topic: CTs with venet exits with CT0's IP address
Goto Forum:
  


Current Time: Fri Sep 20 13:52:50 GMT 2019