Monitor Exim Mail Queue on Sending Hosts + Email Alert
A small bash script designed to run automatically and periodically (CRON) on sending hosts, i.e. shared web servers primarily. This monitors the size of the overall Exim mail queue (both inbound and outbound) and alerts via email when the queue grows beyond a pre-defined limit. Email provides information on top sending domains, or top recipient domains if inbound.
#!/bin/bash
#Dave Byrne
#Exim Mail Queue Alert
############ Edit here #############
_mail_user=serverlogs@vooclients.com
_limit=100
####################################
clear;
_result="/tmp/eximqueue.txt"
_queue="`exim -bpc`"
bold=`tput bold`
normal=`tput sgr0`
if [ "$_queue" -ge "$_limit" ]; then
echo "============================================================================ " > $_result
echo " Current queue is: $_queue (Limit is $_limit)" >> $_result
echo "============================================================================ " >> $_result
echo " " >> $_result
echo "Overall summary of Mail Queue:" >> $_result
echo "`exim -bp | exiqsumm`" >> $_result
echo " " >> $_result
echo " " >> $_result
echo "============================================================================ " >> $_result
echo "Top 10 Addresses being sent TO:" >> $_result
echo "(If address is internal, then mail is inbound. If address is external, then mail is outbound)" >> $_result
echo "============================================================================ " >> $_result
echo " " >> $_result
echo "`exim -bp | awk 'NR % 3 == 2 {print $1}' | sort | uniq -c | sort -rn | head -n10`" >> $_result
echo " " >> $_result
echo " " >> $_result
echo "============================================================================ " >> $_result
echo "Top 10 Addresses being sent FROM:" >> $_result
echo "(If address is internal, then mail is outbound. If address is external, then mail is inbound)" >> $_result
echo "============================================================================ " >> $_result
echo " " >> $_result
echo " " >> $_result
echo "`exim -bp | awk 'NR % 3 == 1 {print $4}' | sort | uniq -c | sort -rn | head -n10`" >> $_result
#Send the mail already
mail -s "Number of mails on `hostname` : $_queue (Limit is $_limit)" $_mail_user < $_result
#For screen friendliness if running in shell manually
cat $_result
fi
#Clearup time
rm -f $_result
-Best run automatically with CRON every few minutes (script is very light weight)
-Uses system ‘mail’ command with no auth’d outbound SMTP connection (ensure your webserver/mailserver is ok with this)