Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For Loop

Status
Not open for further replies.

dsm666

IS-IT--Management
Mar 9, 2004
40
US
Good morning:

This is the output of a log file. Sometimes scripts don't run, and the Command Exit Status is 1.

If it is not equal to 0, I would like an email sent
including the Command-Synce line.

thanks much for your help

May 17 7:46:11 us121 FileAgent[5281] Command-Sync: exec /ceunix/etc/pgp_encrypt.sh ce.17608.7900.B093MRNU.mrncpyrq.txt 17608 /ceunix/log/agent 152914
May 17 7:46:11 us121 FileAgent[5281] Command Exit Status: 0
May 17 7:46:11 us121 FileAgent[5281] Unlink: "/ceunix/stage/ce.17608.7900.B093MRNU.mrncpyrq.txt"
May 17 7:46:26 us121 FileAgent[5281] Cacheing: "/ceunix/stage/B093MRNU.17608.mrncpyrq.txt"
May 17 7:46:56 us121 FileAgent[5281] Processing: size=1510 "/ceunix/stage/B093MRNU.17608.mrncpyrq.txt"
 
Something like this ?
awk '
/Command-Sync/{cs=$0;next}
/Command Exit Status/{
if($NF!=0) print cs"\n"$0
}' /path/to/logfile | mail -s "Your subject" someone@somewhere.com

Hope This Help, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
It worked.
thanks so much PH, much appreciated..
 
I have an example for this with a while loop.

#!/bin/ksh
while true
do
sleep 5
size=`ls -l logfile | awk '{ print $5 }'`
if [ $size -gt 0 ]; then grep "Command-Sync" logfile|while read i
do
mailx -s "subject" "$i" < logfile( or `grep "Command-Sync" logfile`)
done
else sleep 10
fi
done
 
Thanks Ozi403, I was able to use PH.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top