HostOnNet Blog

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

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