1752794 Members
6905 Online
108789 Solutions
New Discussion юеВ

AWK HELP PT TWO.

 
SOLVED
Go to solution
fg_1
Trusted Contributor

AWK HELP PT TWO.

Hello all again.

Yes its me the large pain in the neck.

I am attaching the output from the listed script below. I seem to be having 2 problems here.
1) The 1st columm which seems to be the listed in the top 1/2 of the output file instead of in the table location under the title heading jobid.
2)I cannot figure out why the output for the columm status (columm 2) is printing as the word STATUS instead of the value of STATUS (which could be 0,1,49,150...etc) plus the background color which is specified there as either GREEN for 0 or 1, or RED for other.

Thank you for your help.

###########################################################################
#
# This section of the script will execute the bpdbjobs command utilizing
# the file /home/fgrosb01/.xbpmonrcfg as it's configuration file for the
# output.

bpdbjobs -header -report -format ${BASEDIR}/.xbpmonrcfg > ${INPUT_FILE}

cat ${INPUT_FILE} | awk '{
jobid=substr($0,1,10);
jobtype=substr($0,12,11);
jobstate=substr($0,24,8);
status=substr($0,33,8);
class=substr($0,42,27);
schedule=substr($0,70,18);
client=substr($0,89,26);
mediaserver=substr($0,116,26);
started=substr($0,143,21);
elapsed=substr($0,165,14);
ended=substr($0,180,21)
Kbytes=substr($0,202,13);
files=substr($0,216,13);
compestimated=substr($0,230,11);

if ('status' == 0 || 'status' == 1)
status="status"
else
status="status"

printf("%s%s%s%s%s%s%s%s%s%s\n",jobid,sta,
Kbytes,files,compestimated);
}' > ${TMP_FILE}

print "Netbackup Daily Report" > ${OUTPUT_FILE}
print "" >> ${OUTPUT_FILE}
print "" >> ${OUTPUT_FILE}
print "\n" >> ${OUTPUT_FILE}
print ">" >> ${OUTPUT_FILE}

grep -i ${DATE} ${TMP_FILE} >> ${OUTPUT_FILE}
grep -i ${YDATE} ${TMP_FILE} >> ${OUTPUT_FILE}

print "
jobidstatusclientclassschedulestartedendedkbytesfiles%completed
" >> ${OUTPUT_FILE}
print "" >> ${OUTPUT_FILE}

uuencode ${OUTPUT_FILE} ${OUTPUT_FILE} | $MAIL -m -s "Netbackup Jobs Report ${SCRIPT_EXECUTION_TIME}" ${ADDRESS}
exit 0
mmdcux17@/home/fgrosb01#
7 REPLIES 7
Rodney Hills
Honored Contributor
Solution

Re: AWK HELP PT TWO.

It's been a while since I've done awk (I use perl mainly), but why is status is single quotes in the if statement? Shouldn't the quotes be removed? If you want the contents of status to be displayed then change to the following-

if (status == 0 || status == 1)
status="" status ""
else
status="" status ""

status has to be outside the double quotes.

Hope this helps...

-- Rod Hills

There be dragons...
A. Clay Stephenson
Acclaimed Contributor

Re: AWK HELP PT TWO.

because 'status' is a quoted word; you want to use

if (status == "0" || status == "1")

Now I am really going to confuse you because the above example assumes that status is string context. If you really want to do this correctly (and I assume status is really numeric) then

first change
status = substr($0,33,8)
to
status = substr($0,33,8) + 0
The + 0 is an awk idiom to force numeric context on an expression.

then the comparison should be
if (status == 0 || status == 1)



If it ain't broke, I can fix that.
fg_1
Trusted Contributor

Re: AWK HELP PT TWO.

Rodney,

That answer was right on about the status field problem (problem #2). The codes are actually showing up and the background color is there.

Now the only thing left is why the jobid output is printing out above the table in the output file and not in its assigned columm.

Thank you rodney.

fg_1
Trusted Contributor

Re: AWK HELP PT TWO.

Thank you clay

I have included that into the script too, that was a new one to me. BTW I am still having issues with the jobid output field printing above the table instead of it being lined up in its assigned place. Any Clue?.

Tom Maloy
Respected Contributor

Re: AWK HELP PT TWO.

Looks like your print has %s for jobid in the wrong place:

printf("%s%s<

should (maybe?) be:

printf("%s<

Tom
Carpe diem!
A. Clay Stephenson
Acclaimed Contributor

Re: AWK HELP PT TWO.

Some of your listingb is being trucated so that it's hard to tell but the first thing that I would check is that the grep is actually working.

It would probably be easier to see what's wrong if you attached your source and the output file. Sample input data would certainly make it easier to know what's wrong.

If it ain't broke, I can fix that.
fg_1
Trusted Contributor

Re: AWK HELP PT TWO.

After much trials and tribulations IT WORKS. I want to thank you all for the assist. I will assign points when I get home, my connection here (firewall) is preventing me from assigning them here.