![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Appending the line number and a seperator to each line of a file ? | pjcwhite | Shell Programming and Scripting | 4 | 03-21-2007 01:29 AM |
| appending to sed output of one file into the middle of file | go4desperado | Shell Programming and Scripting | 5 | 02-05-2007 02:20 AM |
| Appending data at the first and last line of a file | brainstormer | Shell Programming and Scripting | 4 | 01-03-2007 10:38 AM |
| Capturing shell script command output | designflaw | Shell Programming and Scripting | 2 | 03-01-2006 04:24 PM |
| capturing output in script | MizzGail | Shell Programming and Scripting | 6 | 06-02-2004 08:44 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
one way
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
|
|
|||||
|
capturing line from script output and appending to a file
Quote:
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 |
|
||||
|
pipe may not be working
I am not sure what exactly is the reason, but the o/p of postsuper -d seems to be not piped to tail command. Try this, Redirect the o/p of postsuper -d to some tempfile. Get the count of messages from the tempfile. Code:
mailq | grep -v "^[^0-9A-Z]+" | grep MAILER-DAEMON | awk '{print $1}' | postsuper -d - >tempfile
no_of_msgs=$(tail -1 tmpfile |awk '{print $3}')
The rest being the same. Remove the tempfile afer the work is over. If this is not working, then do check if the last line is a blank line in the tempfile. Empty lines at the end could also distort the o/p. But I donot know how postsuper works to clearly identify the cause. Hope that helps!! |
|
||||
|
tail should work
Quote:
Code:
rkumar@bdc4reteaix1w: /home/rkumar >ls bkgdtest dead.letter mbox mypipe nohup.out test.pl unix_forum cprog f1.txt myfile newone restart_sshd.sh testpipe.sh whsmith rkumar@bdc4reteaix1w: /home/rkumar >ls | tail -1 whsmith |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|