HostOnNet Blog

PHP Script to alert if mail queue size is above X on Cpanel Server

Looking for Linux Server Admin or WordPress Expert? We can help.

I created a php script to alert if mail queue size if above 100.

<?php

$cmd =  '/usr/sbin/exim -bpc';
$num_mails = exec($cmd);

if ($num_mails > 100)
{
$hostname = exec('/bin/hostname');
$subject = 'Mail queue alert on ' . $hostname;
$mail_text = 'Mail queue on server ' . $hostname . ' have ' . $num_mails . ' mails';
$to_email = 'root@' . $hostname;
mail($to_email, $subject, $mail_text);
}

Saved it as /usr/hostonnet/mail_q_monitor.php

Run it with cronjob

*/10 * * * * /usr/local/bin/php /usr/hostonnet/mail_q_monitor.php >/dev/null 2>&1

Posted in Cpanel Server

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.