(patch for Bash) Embedded web server + Bash

William Park opengeometry-FFYn/CNdgSA at public.gmane.org
Thu Jun 30 20:49:17 UTC 2005


Here is copy of what I posted to <comp.unix.shell>.

I added shell interface to Libwebserver-0.6.0,
    http://stdio.linuxkafe.com/coding/projects/libwebserver-0.6.0-18.zip
which is web server library.  The official version of Libwebserver is
still 0.5.3, and support for that will be added soon.

Yes.  You can now run embedded web server directly from shell script,
totally independent of any external program.  Serving out 2k file is
about 7x slower than Apache.  We're talking about shell script, so it's
fast enough. :-)

Ref:
    http://home.eol.ca/~parkw/index.html#libwebserver

Example:

    func () {
        echo 'Content-Type: text/plain'
        echo
        echo "$*"
        declare -p inetname request alias_request method user pass
    }
    hello () { func Hello; }
    goodbye () { func Goodbye; }
    webserver -p 8080 -l help.log  '* /h*' hello '* /g*' goodbye &

    lynx -head -source http://localhost:8080/hxxx
    lynx -head -source http://localhost:8080/gxxx

Essentially, you register pairs of 'glob' and 'command' to web server:

    - 'glob' will be tested against 'method' and 'uri' of the request
      line.  So, 
	    GET /index.html HTTP/1.0
      will match glob pattern
	    * /in*

    - 'command' can be anything you type on command line.  So, it could
      be shell function, builtin command, external binary, etc.


Normally with Apache and mod_* approach, web/user interface is the main
program, and your data processing application is minor sub-component.
In order to interact with the remote users, you have to run as CGI, save
input data to file or database, and query the saved data (maybe in
another connection and process), process it, and send the result back.

With embedded approach, your data processing application is the main
program, and web interface is the sub-component through which you
interact with remote user.  So, it's upside-down compared to Apache
approach, or vice versa.

Since shell script is for processing data, the embedded approach is far
better.  Indeed, your shell script is now the web server.  Lots of issue
simply disappear, and everything has returned to its natural state of
simplicity and cleanness.

Enjoy!

-- 
William Park <opengeometry-FFYn/CNdgSA at public.gmane.org>, Toronto, Canada
ThinFlash: Linux thin-client on USB key (flash) drive
	   http://home.eol.ca/~parkw/thinflash.html
BashDiff: Super Bash shell
	  http://freshmeat.net/projects/bashdiff/
--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list