Problem

Generate mail server statistics daily on a Postfix mail system.

Analysis

By parsing postfix log files we can extract a lot of information. A great script for this purpose is pflogsumm [1].

For example on Debian/Ubuntu systems you can install it using apt-get

# apt-cache search pflogsumm
pflogsumm - Postfix log entry summarizer
# apt-get install pflogsumm
...
# which pflogsumm /usr/sbin/pflogsumm

You can also download the source and install it manually [1].

Solution

It makes sense to put a script into your /etc/cron.daily directory – all scripts in this directory are usually executed early in the morning. For exact time check your /etc/crontab file, you should see an entry like this:

02 4 * * * root nice -n 19 run-parts --report /etc/cron.daily

Create and edit a file:

/etc/cron.daily/pflogsumm.sh
#!/bin/sh
# Mail Statistics
MAIL_LOG=/var/log/mail/info
MAILHOST="your.mail-server-hostname.com"
RECIPIENT="your@email.com"
# Generate the statistics and mail the result to $RECIPIENT
/usr/sbin/pflogsumm -d yesterday ${MAIL_LOG} | \
mail -s "${MAILHOST} Mail Statistics" ${RECIPIENT}

The -d swich means, that only entries with yesterday’s date will be processed. The script is run with root permissions by default – if you want to change this, add a custom cron entry into your /etc/crontab file.

Now everything is set and there should be a nice mail server summary waiting for you in your mailbox every morning.

References

  1. JIMSUN Postfix Contribs – pflogsumm
Mail server statistics daily on Postfix
Tagged on:                 

Leave a Reply

Your email address will not be published. Required fields are marked *