Big Mail Queue Notification script

February 12, 2006

On a few servers i monitor, there is an ongoing problem of the email queue building up to ridiculous sizes. So, I wrote a script which checks the mail queue size every 5 minutes, and sends me an email if the queue is larger than 500 messages.

Open up your favorite text editor, and paste this code in there:

<?
$exec = system(‘exim -bpc’);
$time = date(“F j, Y, g:i a”);
if($exec >= 800)
{
mail(“you@yourdomain.com”, “big mail queue alert”, “It is $time, and the mail queue currently has $exec messages in it”, “From: mailcheck@yourdomain.com”);
}
else{
die(“nothing to see here”);
}
?>

Change [email]you@yourdomain.com[/email] to whatever your email address is. You can also change “800” to whatever value you want.. 100, 1000, any numerical value you want.

Save the file as mailcheck.php, and stick it in your home directory. eg: /root/mailcheck.php . Depending on your server, you may need to execute as root.

Next, create a cron job for the script by typing the following command as root:

crontab -e

After that, it will open your favorite text editor with your crontab. At the bottom of that file, add this:

0,5,10,15,20,25,30,35,40,45,50,55 * * * * php /path/to/your/mailcheck.php > /dev/null

Then save the file, and it will write the file off to your crontab. After that, there’s nothing else to do. It will check the size of your mail queue every 5 minutes, and if the queue is bigger than the specified size (default: 800 messages), it will shoot an email off to you with the time, and the size of the mail queue.

Advertisements

2 Responses to “Big Mail Queue Notification script”

  1. agent-_- Says:

    Hey ehh… Mikey!

    I want to ask you a favour, I’m ‘discographer’ for Gorillaz-Unofficial.com, a Gorillaz fansite, and by searching around a bit I landed on this blog… You seem to have the ‘Dirty Harry (Paul Mac Remix)’, though I could be completely wrong!
    But if I’m right, could you possibly mail me the mix you have(my mail is in my profile)? Because I need as much as possible info on this song, and since there’s no Australian Gorillaz fan that can help me, I’ve to beg you for help!
    I hope to hear something from you soon,

    oh, and all the best with the allergies… Being ill really sucks…

    G’bye!

  2. mikey Says:

    It’s on the way.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: