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!

How do I print the first field of several lines on one line?? 1

Status
Not open for further replies.

johngiggs

Technical User
Oct 30, 2002
492
US
I am trying to put the names of the jobs that fail in the subject of the mail message. Any help would be greatly appreciated!!

FAIL=`grep FA test | wc -l `
if [ $FAIL -ne 0 ]
then
FAILURES=`grep FA test | awk '{print $1;}'`
grep FA test | awk '{print $1;}' | mailx -s "The Following Job(s) Have Failed $FAILURES"

This script currently will only print the first line of the output in the subject line, however I would like to include all job failures.
 
Here's a quick and dirty way. I'm sure it could be done in a slicker fashion...

FAIL=`grep -c FA test`

if [ $FAIL -ne 0 ]; then
FAILURES=`awk '/FA/ {print $1}' test`
for job in `echo $FAILURES`; do
SUBJECT="$SUBJECT $job"
done
echo whatever | mailx -s "The Following Job(s) Have Failed $SUBJECT" blah@blah.com
fi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top