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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Improve "df" output: create as html table 4

Status
Not open for further replies.

hallux

Programmer
Feb 25, 2003
133
US
Hi everybody,
I send an e-mail out automatically to support personnel that includes output from "df".
Does anybody have any scripts that output a table in html? Or can at least straighten up
the df output.
Thanks alot.
-Brent
 
Thanks, the <pre> tag cleaned it up.
I then created a quick and dirty script (and awk file) to create a table without borders in html.

#!/bin/ksh
{
echo &quot;<BODY BGCOLOR=#000000 TEXT=#FFFFFF LINK=#FFFFFF \ ALINK=#FFFFFF VLINK=#FFFFFF TOPMARGIN=0 LEFTMARGIN=0 RIGHTMARGIN=0 BOTTOMMARGIN=0 >&quot;
echo &quot;<TABLE WIDTH=90% ALIGN=center BGCOLOR=#000093 BORDER=3 CELLPADDING=1 CELLSPACING=1><TR><TD>&quot;
echo &quot;<PRE>&quot;
echo &quot;<table border=&quot;1&quot;>&quot;
echo &quot;<table frame=&quot;void&quot;>&quot; # no borders
df -kI | awk -f df2tb.awk # create individual rows w/ awk
echo &quot;</PRE></TD></TR></TABLE>&quot;
} > df.htm
uuencode df.htm df.htm | mailx -s &quot;df output&quot; \ somebody@somewhere.com # e-mail output to somebody

$ cat df2tb.awk
# df2tb.awk -- send output to html table row format
# input -- output from df -kI in AIX
{ print &quot;<tr>&quot;
print &quot;<td>&quot;$1&quot;</td>&quot;
print &quot;<td>&quot;$2&quot;</td>&quot;
print &quot;<td>&quot;$3&quot;</td>&quot;
print &quot;<td>&quot;$4&quot;</td>&quot;
print &quot;<td>&quot;$5&quot;</td>&quot;
print &quot;<td>&quot;$6&quot;</td>&quot;
print &quot;</tr>&quot;
}
-Brent
 
hey.
this is the cgi-perl script i use for my site...change the url and other headings and it shud work fine..


****************************************************
#!/usr/bin/perl

print &quot;Content-type:text/html\n\n&quot;;

@t=`df | grep -v &quot;Filesystem&quot;`;

print <<EndOfHTML;
<html><head><title>Matrix's file system information</title></head>
<body background=&quot;<br>
<table bgcolor=&quot;#A0B0A0&quot; cellpadding=&quot;3&quot; align=&quot;center&quot;>
<tr bgcolor=&quot;#204D20&quot;><td colspan=&quot;6&quot;><h5></h5></td></tr>
<tr bgcolor=&quot;&quot;>
<td colspan=&quot;6&quot; align=&quot;center&quot; style=&quot;color: #000000&quot;>
<h2>Matrix's File system information</h2>
</td>
</tr>
<tr bgcolor=&quot;#204D20&quot;><td colspan=&quot;6&quot;><h5></h5></td></tr>
<tr colspan=&quot;6&quot;></tr>
<tr bgcolor=&quot;#204D20&quot;>
<td align=&quot;center&quot; style=&quot;color: #FFFFFF&quot;>
<h3>Filesystem</h3>
</td>
<td align=&quot;center&quot; style=&quot;color: #FFFFFF&quot;>
<h3>No. of 1K Blocks</h3>
</td>
<td align=&quot;center&quot; style=&quot;color: #FFFFFF&quot;>
<h3>Used Blocks</h3>
</td>
<td align=&quot;center&quot; style=&quot;color: #FFFFFF&quot;>
<h3>Available Blocks</h3>
</td>
<td align=&quot;center&quot; style=&quot;color: #FFFFFF&quot;>
<h3>% of Usage</h3>
</td>
<td align=&quot;center&quot; style=&quot;color: #FFFFFF&quot;>
<h3>Mount Point</h3>
</td>
</tr>
EndOfHTML

foreach $i (@t)
{
print &quot;<tr bgcolor=\&quot;#A9D79F\&quot;>&quot;;
@i = split (' ', $i);

for ($x = 0; $x <= $#i; $x++)
{
print &quot;<td align=\&quot;center\&quot;><h4>$i[$x]</h4></td>&quot;;
}
print &quot;</tr>&quot;;
}

print <<EndOfHTML2;
<tr bgcolor=&quot;#204D20&quot;><td colspan=&quot;6&quot;><h5></h5></td></tr>
<tr bgcolor=&quot;&quot;>
<td colspan=&quot;6&quot; align=&quot;center&quot; style=&quot;color: #000080&quot;>
<a href=&quot; || <a href=&quot; </td>
</tr>
<tr bgcolor=&quot;#204D20&quot;><td colspan=&quot;6&quot;><h5></h5></td></tr>
</table>
</body>
</html>
EndOfHTML2
****************************************************
 
This ksh script will take the output from df and produce a html page with all the columns aligned and a bar graph showing disk capacity. Try it!

#!/usr/bin/ksh
exec 3> df.html
print -u3 '<HTML><HEAD><TITLE>STATS</TITLE></HEAD><BODY>'
print -u3 '<H3>'$(uname -n)'</H3><TABLE BORDER=2 CELLSPACING=0 CELLPADDING=2>'
print -u3 '<TR><TH>Filesystem</TH><TH>1024-blocks</TH><TH>Used</TH>'
print -u3 '<TH>Available</TH><TH>Capacity</TH><TH>Mounted On</TH></TR>'
df -Pkl |awk 'NR>1 && NF==6'|sort|while read FS SIZE USED FREE PERC MOUNT
do
print -u3 '<TR><TD>'$FS'</TD><TD ALIGN=RIGHT>'$SIZE'</TD>'
print -u3 '<TD ALIGN=RIGHT>'$USED'</TD><TD ALIGN=RIGHT>'$FREE'</TD>'
print -u3 '<TD><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=0><TR>'
print -u3 '<TD WIDTH='$((150*$USED/$SIZE))' BGCOLOR=&quot;black&quot;></TD>'
print -u3 '<TD WIDTH='$((150*$FREE/$SIZE))' BGCOLOR=&quot;gray&quot;></TD>'
print -u3 '<TD><FONT SIZE=-1 COLOR=black> '$PERC'</FONT></TD>'
print -u3 '<TR></TABLE></TD><TD>'$MOUNT'</TD></TR>'
done
print -u3 '</TABLE><P>Generated at '$(date '+%H:%M on %d-%b-%y')'</BODY></HTML>'
exec 3<&-
 
Thanks Sosatan and Ygor:
Very nice, both scripts. I especially liked the bar graph on Ygor's report. These are helpful to see other methods of improving a simple df output and all of the tools you all are using.
Ygor, I have never used the exec command before, could you explain the &quot;exec 3&quot; part of the script. It appears that you are defining 3 as output to a file df.html, then at the end &quot;exec 3<&-&quot; is running all of the preceding lines as input &quot;-&quot; to &quot;3&quot;, and running it as a background process using &quot;&&quot;. So does &quot;exec 3&quot; mean to run everything up to the next &quot;exec 3&quot;?
I appreciate your time and knowledge.
-Brent
 
You've got hold of the wrong end of the stick, 3 is a file handle and the exec special commands are opening/closing output to the file. More info in this thread: thread80-491157
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top