ls2html.sh
Version 0.6

What is it?
===========

ls2html.sh (my version of it at least.. i'm sure there are a bunch of them around) takes a directory listing, and produces an html document that lists directories, symbolic links, and files.  It shows the date that the files were last modified, and for the files, shows their size (in bytes).


Why did it come about?
======================

When I first started working for Linuxberg (http://www.linuxberg.com), I had brought my site over from another server onto their server.  On the old server, for some of the howtos I listed, I relied on apache producing a directory listing for the files that were in there, with names of files, size, date last modified, etc.  On the Linuxberg server however, they had Apache configured to not allow directory listings.  If you tried to go into a directory withough the default html page, it gave you a "Forbidden" note.

I had to fix this, and I didn't feel like writing a doc for each directory since there were just about a hundred or so of them.  I wrote up ls2html.sh, and called it from another file that just listed each directory on each line, and told ls2html.sh to run in that directory to produce a page.

This works well if you never get any new directories.  You can still use ls2html.sh this way, but I suggest using the newly added fdirs.pl.  You just tell it what directory to start in, and it travels down the tree running ls2html.sh in each one.  This works great because you don't have to check the directory listing every day.  :)


How do I use it?
================

First, take a look at the short perl script 'fdirs.pl' that is included with ls2html.sh.  I found this script in the Perl Cookbook, and modified the last line to call up ls2html.sh.  You need to make sure that the last line points to where you have put ls2html.sh  It doesn't matter where it is since fdirs.pl just runs it where it wants to.

Next, take a look at ls2html.sh  You need to change what the default name of the html doc is that ls2html.sh makes.  Currently it is intro.html.  There should be 11 occurances of this within the script.

To run the script, all you do is make sure that you have execute permissions on both scripts.  Do a "chmod +x fdirs.pl ls2html.sh" if you do not, or if you aren't sure.  Now, open fdirs.pl, and choose where you want to start making the html docs.  Currently it is /home/rob/stuff/ls2html.sh.  Change this to whatever you want, but make sure you have read/write permissions on ALL of the directories under that path.  If you don't, then fdirs.pl will go into a loop, and you will have to kill it's pid.  This will be fixed up in the next release.  :)

Anyhoo.. now run ./fdirs.pl and wait for a bit.  After it returns you to a prompt, open up netscape (or lynx, or opera, or kfm, gfm, etc...) and point it to the directory you specified in fdirs.pl.  You will see a dull looking intro.html (or whatever you named it).  You can put whatever html code you want into ls2html.sh to spice it up.  You can take a peek at http://howto.linuxberg.com/ptHOWTO/translations/ to see what I decided to wrap around it.

Known Bugs/Problems
===================
If you do not have read/write access to a directory in it's path, it will loop, and you will need to kill it.  Not a good thing if you have it called from cron or something.  I just need to learn perl a bit more, and get it to die, and move on to the next directory.

In Future Versions
==================
I'd like to have the whole thing written in perl.  Right now I know enough perl to be dangerous, so I decided to keep ls2html.sh seperate.

Have Fun
========

Have fun with it.  This is licenced under the GPL.  Let me know if you have ideas, or bug fixes for this handy little script.

Rob Kennedy
rob@linuxberg.com

