| | |
capturing line from script output and appending to a file
![]() |
•
•
Join Date: Aug 2007
Posts: 3
Reputation:
Solved Threads: 0
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
but what to do with the output? it looks like this:
[etc etc for xx lines]
the LAST line is always this:
OK, putting this together we get something which looks like this:
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
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)
mailq | grep -v "^[^0-9A-Z]+" | grep MAILER-DAEMON | awk '{print $1}' | postsuper -d -
•
•
•
•
postsuper: E657736C82BD: removed
postsuper: E1CAD36C8074: removed
the LAST line is always this:
•
•
•
•
postsuper: Deleted: 127 messages
Shell Scripting Syntax (Toggle Plain Text)
# 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
![]() |
Similar Threads
- Redirecting console output to file (Java)
- Interpreting a script line by line (Shell Scripting)
- Unix Shell Script output..help needed (Shell Scripting)
- appending two java text files (Java)
- doing a lookup script (Shell Scripting)
- How to Script Split for my txt file (VB.NET)
- Please I need help formatting an output file and sorting the names! (C++)
- Output in Text file-How to apply fprintf()? (C)
Other Threads in the Shell Scripting Forum
- Previous Thread: Help with shell script which looks for a set off files within a directory
- Next Thread: Comparing two files and output values that match
| Thread Tools | Search this Thread |





