htmltable 0.1

htmltable is a configurable way to generate HTML tables from, for example, command output, ASCII text files, etc.
htmltable is a configurable way to generate HTML tables from, for example, command output, ASCII text files, etc. The project requires that all input lines have equal numbers of fields. The first line of input is assumed to be a header line.

Configuration

The configuration file for htmltable can take one of two forms, as defined by the "BGSTYLE" variable. A BGSTYLE of "ALT" would have each row with an alternating background colour, defined by the variables BGCOLOR1 and BGCOLOR2. If a BGSTYLE of "NORMAL" is defined, then use the BGCOLOR variable to set the background colour of all rows. Standard HTML colour values should be used. Other variables that are mandatory are CELLSPACING and BORDER. Optional HEADERCOLOR and TABLEBG values can also be defined. Sample configuration files are included in the tarball, and if enough interest in htmltable is shown I will get around to writing some decent documentation!

Notes

You'll need to set "BASEDIR" appropriately within the script (line 15).

The htmltable script has the following usage:

Usage: htmltable.sh [-c ] [-d ] infile
-c - conf file - defaults to $BASEDIR/$CONFDIR/htmltable.conf
-d - delimiter - defaults to 't'

This script is designed to grab simple delimited plain text data and format as tabular HTML output

It can also be used to place command output in an HTML table, but requires more work and pre- processing, as each situation for command output is different...

kevin@foo ~/htmltable $ df -hP | tr -s ' ' | sed 's/Mounted on/Mounted on/' > in/df.in
kevin@foo ~/htmltable $ ./bin/htmltable.sh -c ./conf/htmltable.conf -d' ' ./in/df.in

As you can see, even for a simple df listing, we need to do a few things in order to get the listing in a parsable format.

First, we need to ensure that df outputs in -P (portability) mode, which ensures that each line isn't wrapped. Then, we use tr to -s (squeeze) the spaces.

Next, we use sed to replace "Mounted on" with "Mounted on" which ensures that we can use a space as our delimiter, whilst still displaying the space in the outputted HTML.

Other formats require different approaches, e.g.

kevin@foo ~/htmltable $ cat > /tmp/header
device mountpoint type options
^D
kevin@foo ~/htmltable $ mount | sed -e 's/ on//' -e ' s/ type//' | cat /tmp/header - > mount.in
kevin@foo ~/htmltable $ ./bin/htmltable.sh -c ./conf/htmltable.conf -d' ' ./in/mount.in

We can then test this....

kevin@foo ~/htmltable $ ( echo ""
> ./bin/htmltable.sh -c ./conf/htmltable.conf -d' ' ./in/mount.in
> echo "" ) /tmp/infile.html

Then browse /tmp/infile.html

last updated on:
March 12th, 2007, 15:27 GMT
price:
FREE!
developed by:
Kevin Waldron
license type:
GPL (GNU General Public License) 
category:
ROOT \ Internet \ HTTP (WWW)

FREE!

In a hurry? Add it to your Download Basket!

user rating

UNRATED
0.0/5
 

0/5

Add your review!

SUBMIT