To help combat spammers on your servers, it’s a good idea to be alerted anytime your mail queue has over a certain number of email in it. Typically your mail queue should only grow large if you have a ton of spam in it.
There are many ways you can monitor this. Bellow is just one way to do this.
#!/bin/bash
############################################
# Script created by http://ServerSitters.com
#
# This will check the mail queue, and if larger then $qLimit, it will
# send an email to the address of your choosing letting them know
# how large the mail queue is
#
############################################
################### Configuration ###################
hostname="$(/bin/hostname)";
qSize="$(/usr/sbin/exim -bpc)";
qLimit="700"; #if the queue is larger then this number, an email will be sent to the $sendTo email address
sendTo="[email protected]"; # Separate multiple email addresses with a comma.
sendFrom="root@"$hostname;
############## There should be no need to edit bellow this line ##############
if [ $qSize -gt $qLimit ]; then
echo -e "There are "$qSize "emails in the mail queue" | sed 's/^/To: '"$sendTo"'\nSubject: *ALERT* - Mail queue on '"$hostname"' exceeds limit\nFrom: '"$sendFrom"'\n\n/' | sendmail -t
fi
Typically I will setup a cron to run every 30 minutes, on the hour, and half past the hour.