Postfix has a bunch of queues, and a bunch of stats through other packages, how about some simple shell things if you have multiple instances running?

So, if you have a bunch of postfix processes with independent queues on your system how do you keep track of things like:

  1. which destinations are not accepting email today from you?
  2. which queues need to be flushed?
  3. how many messages in a given timeframe to how many actual recipients?
  4. delete all remaining ‘outdated’ messages in the queue

Simple just use your old friend awk/sed/for… your shell.

To see what things are backed up:

for d in `find postfix-IP* -type f -print | grep def | grep -v pid | grep -v config ` ; do \
  grep "^reci" ${d}  >> /tmp/recips 

awk -F\@ '{print $2}' /tmp/recips  | sort | uniq -c | sort -rn |more

This assumes that all your postfix config directories are in something remote named like: “postfix-IP”, adjust that to your needs, of course. To flush the queues for all your postfix instances:

for d in `ls -d postfix-IP*/config` ; do 
  postqueue -c ${d} -f

(again assuming postfix-IP* is your postfix config/install locations)

To get some stats in a running-total sort of manner:

while : ; do 
   perl -e 'print time()' >> /tmp/mail-stats.log 
   grep "some-uniq-to-line" mail.log | \
                                    grep nrcpt | \
                   awk -F"nrcpt=" '{print $2}' | \
   awk '{TOT=TOT + $1; ALL=ALL + 1} END{ print " connects: " ALL " reciepts: " TOT}' >> /tmp/mail-stats.log 
   sleep 30 

This will make a file in /tmp called mail-stats.log which has about this sort of content:

1174833091 connects: 17405 reciepts: 52372
1174833121 connects: 17433 reciepts: 52481

which you can later parse and report on via perl or excel (yick) or whatever you prefer… ‘connects’ means messages sent through the system, ‘reciepts’ means number of addresses uniquly sent. This is for instances where you send a message like:

To: mom, dad
From: you
Subject: Lookie ma, no hands!

look, I typed with my feets!

Now, to delete all the old messages lost in the queue let’s do this:

for d in `ls -d /full-path/to/postfix-IP*/config` ; do 
  postsuper -c${d} -d ALL defer 

Simple, eh? shell commands… lost in space!