Bash + Embedded web server

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Here is copy of what I posted to <>.

I added shell interface to Libwebserver-0.6.0,
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. :-)



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

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

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.

ThinFlash: Linux thin-client on USB key (flash) drive
We've slightly trimmed the long signature. Click to see the full one.

Site Timeline