capturing line from script output and appending to a file

Reply

Join Date: Aug 2007
Posts: 3
Reputation: bob_the_welder is an unknown quantity at this point 
Solved Threads: 0
bob_the_welder bob_the_welder is offline Offline
Newbie Poster

capturing line from script output and appending to a file

 
0
  #1
Aug 31st, 2007
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
Shell Scripting Syntax (Toggle Plain Text)
  1. 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:

Shell Scripting Syntax (Toggle Plain Text)
  1. # purge the queue (and suppress screen output)
  2. mailq | grep -v "^[^0-9A-Z]+" | grep MAILER-DAEMON | awk '{print $1}' | postsuper -d - >tmpfile >/dev/null 2>&1
  3.  
  4. # count it - and here may well be the problem
  5. msgs=$(tail -1 tmpfile |awk '{print $3}')
  6.  
  7. # prepare the timestamp
  8. dt_time=$(date +'%Y%m%d %H:%M')
  9.  
  10. # stuff the timestamp in the purgefile together with the count
  11. 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!

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
Last edited by bob_the_welder; Aug 31st, 2007 at 10:40 am. Reason: typo
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC