On Mon, Jan 29, 2001 at 04:19:51PM +0100, Stefano Passarella 
<[EMAIL PROTECTED]> wrote:
| I have a shell ( grep and many echo command) , which prints in the
| stdout the HTML tabs. It works well, if it runs as comman ('shell_name
| $1').
| 
| I would use it via WWW. I have readen that I can use CGI and I get
| some informations from cgi.resourceindex.org. Unfortunately, I have
| found only one example.

Shell works just fine for many simple CGIs, and also for some complex
CGIs if you have the right tools. The main thing you need to remember
is that a web page (i.e. the output of your shell script) is a MIME
document, so there are headers denoting its type.

For example:

        echo Content-Type: text/html
        echo
        echo '<H1>Here is some HTML</H1>'

or

        echo Content-Type: text/plain
        echo
        echo 'This is plain text.'
        echo 'See how the < angle brackets > dont do anything?'

or

        echo Content-Type: application/octet-stream
        echo
        cat some-binary-file-the-user-will-download

Another thing is that the web server must know that these scripts are
CGI scripts and not mere data files. On many servers it is enough to
have the script's extension be ".cgi". The #! line will arrange for the
right interpreter to run the script. Thus:

        % cat myscript.cgi
        #!/bin/sh
        echo Content-Type: text/html
        echo
        echo '<H1>Here is some HTML</H1>'

The script (like all scripts) must be be public readable (so the
interpreter - /bin/sh - can open it) and executable (so the OS doesn't
refuse to treat it as executable):

        % chmod 755 myscript.cgi

If your script takes requests, like:

        http://some.where.com/.../myscript.cgi?X=1&Y=2

then these are available in the environment variable $QUERY_STRING,
which I routinely decode into normal shell variables with
query_string2sh:

        http://www.zipworld.com.au/~cs/scripts/query_string2sh

which also needs hexify:

        http://www.zipworld.com.au/~cs/scripts/hexify

You use it like this:

        eval "`query_string2sh`"
        echo "X is $PARAM_X"
        echo "Y is $PARAM_Y"

(It stuffs PARAM_ onto the front of the variable names so that it doesn't
trash your normal variables).
--
Cameron Simpson, DoD#743        [EMAIL PROTECTED]    http://www.zip.com.au/~cs/

Carpe Datum     - John Sloan <[EMAIL PROTECTED]>



_______________________________________________
Redhat-list mailing list
[EMAIL PROTECTED]
https://listman.redhat.com/mailman/listinfo/redhat-list

Reply via email to