Disk Space Utilization in HTML format working in one environment and not working on the other

Hi Team,

I have written the shell script which returns the result of the disk space filesystems which has crossed the threshold limit in HTML Format. Below mentioned is the script which worked perfectly on QA system.

df -h | awk -v host=`hostname` '
BEGIN {
print "<table border="4" bordercolor=greencellpadding=\"3\" cellspacing=\"7\">"
printf "<tr BGCOLOR=#FFAF6E><td><B>%s</B></td></tr>\n", host
print "<tr BGCOLOR=#EBE3E3><th>Filesystem</th><th>Size</th><th>Used</th><th>Avail</th><th>Used%</th><th>Mounted on</th></tr>"
}
NR>1&&($5+0)>70{
     print "<tr>"
    for( i = 1; i <= NF; i++ ) {
printf "%s", "<td"
      if (i==5&&$i+0>85) printf " bgcolor=#FF2C2C"
       else if (i==5&&$i+0>=75) printf " bgcolor=#FFC200"
       print ">" $i "</td>"
    }
     print "</tr>"
  }
   END { print "</table>" }' > DSReport.html

But the same thing was not working on PRODUCTION system. :(:frowning:

For PROD system, How we login is using swrap <admin>@<servername>

then we will execute the script.

The result displayed is actually blank tables even though there are filesystems which crossed the threshold. I am getting Headers only as output.

Please help me to resolve this issue. QUICK RESPONSE IS APPRECIATED. Thank you.

Not an order , My biggest request as i Need to complete this task before sunday.

What is swrap?

If you get an empty table, then the first place to look is the the df -h command.

Start with the basics -
Use your login procedure (whatever that is) on PROD:

df -h  && echo 'OK'  || echo 'df command failed'

swrap is like sudo

I tried the command df -h && echo 'OK' || echo 'df command failed' and got the output as normal df -h and in the end 'OK'.

I think the df -h doesn't have any problem. IS there any other way to get the result ?

Could it be that your production environment is a Solaris/SunOS system?

You may need to change awk to /usr/xpg4/bin/awk or nawk

1 Like

No, Its linux OS only both PROD and QA.

Script was working fine in outside local systems BUT why not in PROD ? :frowning:

Dear All,

I have made the below changes to make the script generates a HTML report. Now I need your help . If the filesystems crossed the threshold matching the below code , as per the code it should create a DSReport.html file or else it should create a text file stating that NO ISSUES REPORTED on the server.

Please help me to modify this code. Please

df -Ph | awk -v host=`hostname` '
BEGIN {
print "<table border="4" bordercolor=greencellpadding=\"3\" cellspacing=\"7\">"
printf "<tr BGCOLOR=#FFAF6E><td><B>%s</B></td></tr>\n", host
print "<tr BGCOLOR=#EBE3E3><th>Filesystem</th><th>Size</th><th>Used</th><th>Avail</th><th>Used%</th><th>Mounted on</th></tr>"
}
NR>1&&($5+0)>70{
     print "<tr>"
    for( i = 1; i <= NF; i++ ) {
printf "%s", "<td"
      if (i==5&&$i+0>85) printf " bgcolor=#FF2C2C"
       else if (i==5&&$i+0>=75) printf " bgcolor=#FFC200"
       print ">" $i "</td>"
    }
     print "</tr>"
  }
   END { print "</table>" }' > DSReport.html 

Try

df -Ph | awk -v host=`hostname` '
BEGIN   {print "<table border="4" bordercolor=greencellpadding=\"3\" cellspacing=\"7\">"
         printf "<tr BGCOLOR=#FFAF6E><td><B>%s</B></td></tr>\n", host
         print "<tr BGCOLOR=#EBE3E3><th>Filesystem</th><th>Size</th><th>Used</th><th>Avail</th><th>Used%</th><th>Mounted on</th></tr>"
        }

NR > 1 &&
($5+0) > 70     {XVAL = 1
                 print "<tr>"
                 for( i = 1; i <= NF; i++ )     {printf "%s", "<td"
                                                 if (i==5 && $i+0 > 85)         printf " bgcolor=#FF2C2C"
                                                 else if (i==5 && $i+0 >= 75)   printf " bgcolor=#FFC200"
                                                 print ">" $i "</td>"
                                                }
                 print "</tr>"
                }
END             {print "</table>"
                 exit XVAL+0
                }
' > DSReport.html && { echo "NO ISSUES REPORTED" > DSResult.txt; rm DSReport.html; }
1 Like

Just for the record: df -Ph is a bit schizophrenic, because -P asks for output in POSIX-format and -h asks for output in "human readable" format (whatever that may be in Linux, i personally find the changing units annoying, but that is probably personal taste).

For portable scripts it is recommended to only use -P and to parse the output it generates. This will be the same not only in different versions of Linux but also other (POSIX-compliant) UNIX-systems.

I hope that helps.

bakunin

Hi ,
The Output for the code which we modified is printing along with a 1 in the top and bottom. PFB result for reference. How to avoid printing 1 in the top and bottom of the result or else script works perfectly fine.

1 1 1 1 1 

Filesystem

Size

Used

Avail

Used%

Mounted on

/dev/mapper/rootdg-rootdgvol8 395M 323M 52M 87% /opt/OV 
/dev/mapper/rootdg-rootdgvol1 2.9G 2.1G 659M 77% /usr 
/dev/mapper/dg01-vol03 15G 12G 2.8G 81% /appl/ae12prod 
/dev/mapper/dg01-vol04 50G 34G 14G 72% /opt/FileNet 
usqasny001:/BS04343_EDM_AM_PROD01 500G 351G 150G 71% /opt/LoadRunner 
1 

Sorry unable to insert the image from my desktop. Kindly let me know how to avoid 1 in the beginning and end.

df -Ph | awk -v host `hostname -s` '
BEGIN  {print "<table border="4" bordercolor=greencellpadding=\"3\" cellspacing=\"7\">"
        #printf "<tr BGCOLOR=#FFAF6E><td><B>%s</B></td></tr>\n", host
        print "<tr BGCOLOR=#EBE3E3><th>Filesystem</th><th>Size</th><th>Used</th><th>Avail</th><th>Used%</th><th>Mounted on</th></tr>"
        }

NR > 1 &&
($5+0) > 70    {XVAL = 1
                print "<tr>"
                for( i = 1; i <= NF; i++ )    {printf "%s", "<td"
                                                if (i==5 && $i+0 > 85)        printf " bgcolor=#FF2C2C"
                                                else if (i==5 && $i+0 >= 80)  printf " bgcolor=#FFC200"
                                                print ">" $i "</td>"
                                                }
                print "</tr>" XVAL
                }
END            {print "</table>"
print XVAL+0
                exit XVAL+0
                }
' > DSReport.html && { echo "NO ISSUES REPORTED" > DS_Noissues.txt; rm DSReport.html; }

You print XVAL - once for each file system under alarm, and once in the END section.

I am not getting you :frowning: .. Could you please help to rephrase it in the code if possible. Sorry for bothering :frowning: _/\_

Look into the code you posted for something with a print in it and an XVAL . Comment out those lines and test. You may need to keep printing the "</tr>" , though.

Friends/Masters,

I need your help to create one property file which should have input like

FILESYSTEM WARNING CRITICAL
/ 80 90
/home 85 95
/opt/ 86 92

and the diskspace script should monitor the inputs from the filesystem and send email only when critical limit reached the percentage mentioned or else it should not.

the email format should be in HTML format.

In my script, I have provided all inputs in a single shell file. BUt they need a property file as input now instead of hard coding in a single shell file.

please help me out with one script and how to bring the input file inside and trigger the email _/\_

You told us that you wrote the code you showed us in post #1 in this thread. It doesn't produce exactly the output that you want, but it does show that the author of that code had a basic understanding of coding principles.

You were given some code that seems to do what you wanted. You modified that code to add some debugging output.

You have been told exactly what is wrong in your code.

You have been told how to easily fix your code.

And yet you are unwilling or unable to remove one word from one line in your code and to remove one other line of code. (Even when the word and line that need to be removed are text that you added.)

Did you write the code you showed us in post #1? Is fixing this code part of a homework assignment?

We are here to help you learn how to write your own code; not to act as your unpaid programming and secretarial staff.