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:
PHP Code:
<?
$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
you@yourdomain.com 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:
Code:
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.