Simple Exim monitoring

Published Wed 06 March 2013 by Daniel W

This is a simple script that I've begun developing to output some useful information from the Exim logs that can be used for analysis of emails being sent via SMTP authentication.

Whilst fairly basic, the script looks like this:

# cPanel Simple Monitor
echo --------------------------- > $WEBROOT
echo `hostname` >> $WEBROOT
echo `date` >> $WEBROOT
echo Mailbox Auth: >> $WEBROOT
perl -lsne '/$today.* \[([0-9.]+)\]:.+dovecot_(?:login|plain):([^\s]+).* for (.*)/ and $sender{$2}{r}+=scalar (split / /,$3) and $sender{$2}{i}{$1}=1; END {foreach $sender(keys %sender){printf"Recip=%05d Hosts=%03d Auth=%s\n",$sender{$sender}{r},scalar (keys %{$sender{$sender}{i}}),$sender;}}' -- -today=$(date +%F) /var/log/exim_mainlog | sort | tail -n 5 >> $WEBROOT
echo --------------------------- >> $WEBROOT

This should give you something like the following:
Mon Jul 18 17:01:00 AEST 2016
Mailbox Auth:
Recip=00016 Hosts=002 [email protected]
Recip=00017 Hosts=001 [email protected]
Recip=00032 Hosts=009 [email protected]
Recip=00036 Hosts=001 [email protected]
Recip=05072 Hosts=306 [email protected]

You can then schedule this with a Cronjob.

© – published with Pelican, theme by djw4