The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #3 (permalink)  
Old 08-30-2007
wally_welder's Avatar
wally_welder wally_welder is offline
Registered User
  
 

Join Date: Aug 2007
Location: Dongen, Netherlands
Posts: 2
capturing line from script output and appending to a file

Quote:
Originally Posted by ranj@chn View Post
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