![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
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 07: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}')
Code:
dt_time=$(date +'%Y%m%d %H:%M') 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}')
|
|
||||
|
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 |
|
||||
|
Code:
mailq | awk '!/^[^0-9A-Z]+/ && /MAILER-DAEMON/{
cmd = "postsuper -d " $1
cmd | getline #or system(cmd)
close(cmd)
}'
|
| Sponsored Links | ||
|
|