Quote:
Originally Posted by ranj@chn
One way would be to get pipe the o/p and filter out the last line and get the no of deleted messages from there & assign it to a variable.
Code:
no_of_msgs=$(mailq | grep -v "^[^0-9A-Z]+" | grep MAILER-DAEMON | awk '{print $1}' | postsuper -d - | tail -1 | awk '{print $3}')
Format the date to get the date-time stamp required
Code:
dt_time=$(date +'%Y%m%d %H:%M')
Now echo this to a file where you want to log this.
Code:
echo "$dt_time - ${no_of_msgs}" >>cron_purges
|
That does some rather interesting things:
1. It does run the deletions successfully, but outputs verbosely to screen in the original format
2. It does write a timestamp to the file cron_purges
but
3. Doesn't capture the number (represented as "xxx" below) appearing in the last line of output:
postsuper: Deleted: xxx messages
Unfortunately, I don't know enough about the syntax to mess around with possible alternatives in order to offer a suggestion...so, I'm a bit stumped still.
Regards & Thanks!
-Wally