Skip to content

Instantly share code, notes, and snippets.

@dev01d
Last active September 23, 2018 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dev01d/64f35ff2e4696da50ace884c9cdf0a5a to your computer and use it in GitHub Desktop.
Save dev01d/64f35ff2e4696da50ace884c9cdf0a5a to your computer and use it in GitHub Desktop.
A script for monitoring Exim undelivered mail queue.
#!/usr/bin/env bash
#
# A script for monitoring Exim undelivered mail queue.
# intended to be used in conjunction with a cron job.
#
# Email recipient
alertEmail=#Add email here.
# Set the alert threshold here
queueThreshold=100
# result log location
resultLog="/tmp/mail-Queue.log"
# Variables
currentQueue="`exim -bpc`"
logTime=$(date)
if [ "$currentQueue" >= "$queueThreshold" ];
then
echo "Mail Queue Threshold observed." > $resultLog
echo $logTime >> $resultLog
echo "Current queue is: $currentQueue" >> $resultLog
echo "Mail queue summary" >> $resultLog
echo "`exim -bp | exiqsumm -c`" >> $resultLog
# Optional search with greater detail to be used in lieu of preceding line.
#echo "`exim -bp | exipick -bpc <search term>`">> $resultLog
mail -s "Mail Queue Threshold observed for `hostname` : $currentQueue" $alertEmail < $resultLog
cat $alertEmail
exit
else
exit
fi
# Optional garbage collection because tmp is temp.
# Comment rm and uncomment cat for debugging alert mail send issues.
#cat $resultLog
rm $resultLog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment