bob_the_welder 0 Newbie Poster

Hi Folks!
This should be trivial, but because of this guy Murphy, it's turned out to be anything but. OK, here goes:

Requirement:
On a mail gateway running postfix,
1. dump any mail from MAILER-DAEMON via the "postsuper" command.
2. Record how many messages get dumped into a flat file (called, rather unimaginatively, "cron_purge") with a timestamp.
------
3. (Beyond the scope of this) later on, graph the results of purges by hour/day/week/month/year.

Method:
1. Do the PURGE

mailq | grep -v "^[^0-9A-Z]+" | grep MAILER-DAEMON | awk '{print $1}' | postsuper -d -

but what to do with the output? it looks like this:

postsuper: E657736C82BD: removed
postsuper: E1CAD36C8074: removed

[etc etc for xx lines]
the LAST line is always this:

postsuper: Deleted: 127 messages

OK, putting this together we get something which looks like this:

# purge the queue (and suppress screen output)
mailq | grep -v "^[^0-9A-Z]+" | grep MAILER-DAEMON | awk '{print $1}' | postsuper -d - >tmpfile >/dev/null 2>&1

# count it - and here may well be the problem
msgs=$(tail -1 tmpfile |awk '{print $3}')

# prepare the timestamp
dt_time=$(date +'%Y%m%d %H:%M')

# stuff the timestamp in the purgefile together with the count
echo "$dt_time - $msgs" >>cron_purges

The number is not ending up in the cron_purges file. The timestamp is OK, but at the right side of the "-" there is no number. As I remarked at the beginning, this ought to be minor in nature, but I'll be darned if I can get the thing to function. As always, a fresh pair of eyes looking at this will see things with greater clarity than the fog that seems to be between me and my terminal right now.

Ideas would be most gratefully received! :confused:

May the Magnificent Arc and its Gaseous Shield be with you all. Do not weld anything while standing in ankle deep water. Use eye protection at all times, and avoid flying slag like the plague.
Warm Regards,
Bob The Welder

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.