User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 456,442 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,610 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 2247 | Replies: 0
Reply
Join Date: Aug 2007
Posts: 3
Reputation: bob_the_welder is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bob_the_welder bob_the_welder is offline Offline
Newbie Poster

Question capturing line from script output and appending to a file

  #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
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!

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
AddThis Social Bookmark Button
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 1:46 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC