Create a file called mailqueue.sh.
vim /root/mailqueue.sh
Add the following code.
#!/bin/bash
EMAIL=”youraddress@mail.com”
MQUEUE=`find /var/spool/exim/input -name ‘*-H’ | wc -l | sed -e “s/ //g”`
if [ $MQUEUE -gt 200 ]; then
echo “Mail queue at `hostname` has $MQUEUE messages!!!” | mail -s “CRITICAL ALERT: Mail queue” $EMAIL
fi
Save the file and schedule a cronjob to execute the file on every minute.
# crontab -e
and set the following cronjob
* * * * * /bin/sh /root/mailqueue.sh
Cpanel email queue notification script.