0

I am trying to create a script which uses text file as input, compares values against a threshold and create a html report. My data populates just fine, but it is not rendering colors as expected, need guidance on the same please, I mean how to use this variable in td ?

input file:

6 30 OK
5 30 OK
70 30 NOK
56 30 NOK
8 30 OK
52 30 NOK
22 30 OK

and below is my awk command:

awk 'BEGIN{
FS=" "
print  "<TABLE border=1 cellspacing=0 cellpadding=3><TR><TH>HOST</TH><TH>APP_HOST1</TH><TH>APP_HOST2</TH><TH>APP_HOST3</TH><TH>APP_HOST4</TH><TH>APP_HOST5</TH><TH>DB_HOST1</TH><TH>DB_HOST2</TH></TR>"
print "<TR><TD>DISK_ROOT</TD>"
}
 NR>=1{
bgcolor=" bgcolor=green"
if($3=="NOK"){ bgcolor=" bgcolor=red"}
printf "<TD $bgcolor>"$1"</TD>"
}
 END{
print "</TABLE>"
 }
'  ${logdir}/Disk_Space.log >> $stat_dir/html/report_Disk.html

1 Answer 1

1

I'm not sure about the output that you are expecting, but this could work?

awk 'BEGIN{
FS=" "
print  "<TABLE border=1 cellspacing=0 cellpadding=3><TR><TH>HOST</TH><TH>APP_HOST1</TH><TH>APP_HOST2</TH><TH>APP_HOST3</TH><TH>APP_HOST4</TH><TH>APP_HOST5</TH><TH>DB_HOST1</TH><TH>DB_HOST2</TH></TR>"
print "<TR><TD>DISK_ROOT</TD>"
}
 NR>=1{
if($3=="NOK")printf "<TD bgcolor=\"red\">"$1"</TD>"
else printf "<TD bgcolor=\"green\">"$1"</TD>"
}
 END{
print "</TABLE>"
 }
'  Disk_Space.log >> ./report_Disk.html

Image description

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.