formatting output in html


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting formatting output in html
# 1  
Old 08-03-2006
formatting output in html

hello all. I was hoping someone may have an idea or two.

I'm throwing together a shell script that does a lot of application and system level data collection. The idea is is you run it before/after restarting an application for later analysis. A lot of stuff is collected... resource stats, logs, db status, mirroring, thread dumps, pstacks, and so forth. Currently the output is being rolled up into a tar ball.

The question is, can anyone point me in the right direction on how to format the output in HTML for ease of review?

many thanks.
# 2  
Old 08-03-2006
Outputting HTML is easy. HTML is text.

Code:
#!/bin/sh

echo "<html><body>This is HTML</body></html>"

PHP is a language specifically designed to present results in HTML. It has the power of a full scripting language, and you can intermix raw HTML and PHP with ease.
Code:
<html>
  <body>
<?php   $dspec=array(   1       =>      array("pipe", "w")      );
        $proc = proc_open("ps ux", $dspec, $pipes );

        ($proc) || die("Couldn't run 'ps ux'");         ?>
    <table width='100%'>
      <tr>
<?php   $line=fgets($pipes[1]);
        $titles=preg_split("/[\s]+/",$line);

        for($n=0; $n<sizeof($titles); $n++)
        {                                               ?>
        <th><?=$titles[$n]?></th>
<?php   }                                               ?>
      </tr>
<?php   while($line=fgets($pipes[1]))
        {
                $titles=preg_split("/[\s]+/",$line);
                                                        ?>
      <tr>
<?php           for($n=0; $n<sizeof($titles); $n++)
                {                                               ?>
        <td><?=$titles[$n]?></td>
<?php           }                                               ?>
     </tr>
<?php   }       ?>
    </table>
  </body>
</html>
<?php   proc_close($proc);      ?>

This will produce an HTML table like so:

Code:
<html>
  <body>

    <table width='100%'>
      <tr>
        <th>USER</th>
        <th>PID</th>
        <th>%CPU</th>

        <th>%MEM</th>
        <th>VSZ</th>
        <th>RSS</th>
        <th>TTY</th>
        <th>STAT</th>
        <th>START</th>

        <th>TIME</th>
        <th>COMMAND</th>
        <th></th>
      </tr>

      <tr>
        <td>apache</td>
        <td>13019</td>

        <td>0.0</td>
        <td>3.6</td>
        <td>16120</td>
        <td>8096</td>
        <td>?</td>
        <td>S</td>

        <td>Jul30</td>
        <td>0:00</td>
        <td>/usr/sbin/apache2</td>
        <td>-D</td>
        <td>USERDIR</td>
        <td>-D</td>

        <td>DEFAULT_VHOST</td>
        <td>-D</td>
        <td>SSL</td>
        <td>-D</td>
        <td>PHP5</td>
        <td>-d</td>

        <td>/usr/lib/apache2</td>
        <td>-f</td>
        <td>/etc/apache2/httpd.conf</td>
        <td>-k</td>
        <td>start</td>
        <td></td>

      </tr>

      <snip for brevity>

    </table>
  </body>
</html>

...obviously not perfect, since PS doesn't use tabs for seperators(for reasons I can't imagine), but hopefully shows the idea.

PHP can be run on a web server -- the UNIX forums run on it -- in which case the code is executed and the results presented to you. You can also run it from the command prompt directly via 'php file.php'.
# 3  
Old 08-03-2006
I appreciate the idea. The thing is, this tool is being written for machines that are deployed w/ out php. What I'm looking to do is have the output in a single file, FAQ-like form with a table of contents at the top. I have multpile functions defined in a ksh script and each will need it's own table of contents entry which takes you to the desired output. Right now each function is redirected to an output file and all output files are rolled into the tarball at the end. Here's an abbreviated version to get the idea across...


Code:
#!/bin/ksh

# global var
DATE=`date '+%m%d%y_%H%M'`


# define logging variables

logs_define () {
 export TANKDIR=/var/tmp/dataCollect_tmp_.$DATE
 export VERLOG=$TANKDIR/rpm_version.log
 export METALOG=$TANKDIR/metadevices.log 
 export PROCLOG=$TANKDIR/allprocs.log
}

# create the directory where output will be stored

holding_tank_mk () {
 mkdir $TANKDIR
 echo "All output files are being written into "$TANKDIR"/"
 echo "This directory will be removed and it's contents placed in a tarball at the end of the run."
}

# grab the rpm version info

get_rpmversion () {
 echo ""
 echo "Gathering rpm version information..."
 rpm -qa|sort >> $VERLOG
}

# get metastat output

get_metastat () {
 echo "Gathering disk mirroring information..."
 echo "#####  metastat output  #####" >> $METALOG
 metastat >> $METALOG
 echo "" >> $METALOG
 echo "#####  metadb output  #####" >> $METALOG
 echo "" >> $METALOG
 metadb -i >> $METALOG >> $METALOG
}

# snapshot of all system processes running

get_allprocs () {
 echo "Gathering 'ps -ef' output..."
 /usr/ucb/ps -auxwww >> $PROCLOG
}

# tar and zip contents of output diirectoy

bundle () {
 export TARBALL=/var/tmp/dataCollect_.$DATE.tar
 tar cvf $TARBALL $TANKDIR
 gzip $TARBALL
 echo ""
 echo "Information has been collected and placed in the following file..."
 echo "\t"$TARBALL.gz
 echo ""
 echo ""
}

# delete the output directory

holding_tank_rm () {
 exec rm -rf $TANKDIR
}


# execute

logs_define
holding_tank_mk
get_rpmversion
get_metastat
get_allprocs
bundle
holding_tank_rm

# 4  
Old 08-03-2006
No PHP? Hardly the end of the world, since anything that prints text can make HTML. You might do something like this:

Code:
#!/bin/sh
DATE=`date '+%m%d%y_%H%M'`

# Print beginning of webpage
function html_header
{
    cat <<END
<html>
  <head><title>${1}</title></head>
  <body>
    <h3>${1}</h3>
    <!-- Table of Contents links -->
    <p>
      <a href='#rpmversion'>RPM Versions</a>
      <a href='#processes'>Processes</a>
    </p>
END
}

function html_footer
{
  cat <<END
  </body>
</html>
END
}

function html_title
{
  echo "<h3><a name='#${2}'>$1</a></h3>"
}

function rpm_versions
{
  html_title "RPM Versions" "rpmversion"
  echo "<pre>"
  rpm -qa|sort
  echo "</pre>"
}

function get_allprocs
{
  html_title "All Running Processes" "processes"
  /usr/ucb/ps -auxwww
}

html_header "Report Summary for ${DATE}"
rpm_versions
get_allprocs
html_footer

produces output like:
Code:
<html>
  <head><title>Report Summary for 080306_0836</title></head>
  <body>
    <h3>Report Summary for 080306_0836</h3>
    <!-- Table of Contents links -->
    <p>
      <a href='#rpmversion'>RPM Versions</a>
      <a href='#processes'>Processes</a>
    </p>
<h3><a name='#rpmversion'>RPM Versions</a></h3>
<pre>
(stuff)
</pre>
<h3><a name='#processes'>All Running Processes</a></h3>
<pre>
(stuff)
</pre>
  </body>
</html>

# 5  
Old 08-03-2006
much appreciated.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

HTML formatting in shellscript

I have written one script which connects to MYSQL database, fires one select query and send the results over an email, if there is any Output. But the Output which I am receiving over email is in text format. I need to get it dispalyed in tabular format to ensure better readability. Below is... (3 Replies)
Discussion started by: Sambit Sahu
3 Replies

2. Shell Programming and Scripting

[Solved] Sending a HTML email from cli loses formatting.

Hi, I have a .sh file, to email a report of our backups from a linux machine. It looks like this (minus a few bits): echo "HELO $host.$domain" sleep 1 echo "mail from: vdrreport@$domain" sleep 1 echo "rcpt to:$mailto" sleep 1 echo "data" sleep 1 echo "subject: $host VDR-Report... (2 Replies)
Discussion started by: cognito
2 Replies

3. Shell Programming and Scripting

Formatting output

Hi, I have a file like this -------------------------- 1 aaa xxx 55 -------------------------- 1 aaa www 32 -------------------------- 2 bbb yyy 11 -------------------------- 2 bbb zzz 34 ------------------------- 2 bbb ttt ... (3 Replies)
Discussion started by: tdev457
3 Replies

4. UNIX for Dummies Questions & Answers

How would i mail in html format?(Formatting Help)

I have written a scripts that checks the load average of server and if it is more than 5 it send a mail describing Current Load Average and High CPU/RAM processes . The problem is I want to send these information in html form .I have done necessary coding to do the same but whenever i try to... (7 Replies)
Discussion started by: pinga123
7 Replies

5. UNIX for Dummies Questions & Answers

How would i mail in html format?(Formatting Help)

I have written a scripts that checks the load average of server and if it is more than 5 it send a mail describing Current Load Average and High CPU/RAM processes . The problem is I want to send these information in html form .I have done necessary coding to do the same but whenever i try to... (0 Replies)
Discussion started by: pinga123
0 Replies

6. Shell Programming and Scripting

Output formatting

I have input file in this way John 1234 BASIC 26000 John 1234 ALLOWC 01550 John 1234 INCER 01700 John 1234 REL 20000 Debi 2345 BASIC 29000 Debi 2345 ALLOWC 01600 Debi 2345 INCR 01900 Debi 2345 REL ... (8 Replies)
Discussion started by: vakharia Mahesh
8 Replies

7. Shell Programming and Scripting

html formatting using awk

Hi I have a file as given below: <table border=1> <TR><TH>Script Name</TH><TH>CVS Status</TH><TH>Script Location</TH></TR> <TR><TD><CENTER>Work Area: /home/ustst/</CENTER></TD></TR> <TR><TD><CENTER>admin_export.sh</CENTER></TD><TD><CENTER>Locally... (1 Reply)
Discussion started by: sudvishw
1 Replies

8. Shell Programming and Scripting

formatting output

Sorry for being a n00b, but I'm having a lot more trouble than I should with formatting the output to the program I finally completed. I'm basically looking for the linux equivalent to setw( ) from c++ so that I can print things in columns like this (but without the underlines lol): MISSPELLED: ... (4 Replies)
Discussion started by: aikaterinimak
4 Replies

9. Shell Programming and Scripting

more help with formatting ls output...

Ok, for a fun project, my goal is to replicate the style of "catalog" on an old apple ] *A 002 SOMEAPPLESOFTFILE B 004 SOMEFILE T 006 SOMETEXT I 002 SOMEINTEGERFILE The first character is either " " or "*" depending on if the file is locked or not. Next is the filetype, so in... (1 Reply)
Discussion started by: patrick99e99
1 Replies

10. Shell Programming and Scripting

Formatting the output

Hi all, Have the following code(1) producing the results(2 & 3). Would like to know if there is a way to format the two reports created in a similar fashion. IE - The first is formatted nicely as a result of the echo "$xmpbdate $xavgs" >> $xmpbrpt However when I attempt to do the same on... (7 Replies)
Discussion started by: Cameron
7 Replies
Login or Register to Ask a Question