Reading STDIN to a bash CGI

Reading STDIN to a bash CGI

Post by Chuck Carso » Thu, 02 Aug 2001 01:30:36



I want to use bash for some CGI stuff but cannot seem to get the query
string from the browser. I used bash years ago so I do not know if Apache
or bash itself has changed in this regard. (Please do not suggest another
language, I have written CGI is nearly every language but I must use bash
for this explicit project)

I have tried reading directly from STDIN with read, I have tried
accessing the ENV variables but QUERY_STRING or CONTENT_LENGTH is not
getting set. All the other CGI variables seem to be getting set
correctly.

GATEWAY_INTERFACE is getting set to CGI/1.1 which is correct.

Maybe I am making a bonehead mistake, been doinf EJB/servlets for the
past year, CGI is a bit foggy.

Can anyone give me some suggestions?

Thanks,
CC

 
 
 

Reading STDIN to a bash CGI

Post by John Austi » Thu, 02 Aug 2001 03:17:07


It would help if you posted a short example of something that does not work.

Can you run a CGI written in another language ? Try one of the examples
that comes with Apache.  You have to try this first to determine whether
you have a problem with CGI in general (your Apache configuration)
or with bash CGI's in particular.


I want to use bash for some CGI stuff but cannot seem to get the query
string from the browser. I used bash years ago so I do not know if Apache
or bash itself has changed in this regard. (Please do not suggest another
language, I have written CGI is nearly every language but I must use bash
for this explicit project)

I have tried reading directly from STDIN with read, I have tried
accessing the ENV variables but QUERY_STRING or CONTENT_LENGTH is not
getting set. All the other CGI variables seem to be getting set
correctly.

GATEWAY_INTERFACE is getting set to CGI/1.1 which is correct.

Maybe I am making a bonehead mistake, been doinf EJB/servlets for the
past year, CGI is a bit foggy.

Can anyone give me some suggestions?

Thanks,
CC

 
 
 

Reading STDIN to a bash CGI

Post by David Efflan » Thu, 02 Aug 2001 10:17:40



> I want to use bash for some CGI stuff but cannot seem to get the query
> string from the browser. I used bash years ago so I do not know if Apache
> or bash itself has changed in this regard. (Please do not suggest another
> language, I have written CGI is nearly every language but I must use bash
> for this explicit project)

> I have tried reading directly from STDIN with read, I have tried
> accessing the ENV variables but QUERY_STRING or CONTENT_LENGTH is not
> getting set. All the other CGI variables seem to be getting set
> correctly.

Try listing all env variables first to see what is there:

#!/bin/sh
echo Content-type: text/plain
echo
env

If you append a proper query string to the URL (or GET method for a form)
something should show up in QUERY_STRING.  For example using the above
script with ?hello appended to the url, among env I see:

QUERY_STRING=hello

If you are trying to do POST method, then CONTENT_LENGTH is required
because there is no other way to determine end of data (no newline or
eof).  Looking through the Adv-Bash-Scr-HOWTO in Linux, 'read' would not
work (no way to specify length), but possibly 'dd' which can read a
specified number of bytes (default is from stdin).

--
David Efflandt  (Reply-To is valid)  http://www.de-srv.com/
http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/

 
 
 

Reading STDIN to a bash CGI

Post by Rhug » Sat, 04 Aug 2001 02:47:29



Thanks for the help, it ended up being some problems with shared mem
and a custom module we wrote. We upgraded to SuSE 7.2 and some things
got broken.

Thanks,
Chuck


>> I want to use bash for some CGI stuff but cannot seem to get the query
>> string from the browser. I used bash years ago so I do not know if Apache
>> or bash itself has changed in this regard. (Please do not suggest another
>> language, I have written CGI is nearly every language but I must use bash
>> for this explicit project)

>> I have tried reading directly from STDIN with read, I have tried
>> accessing the ENV variables but QUERY_STRING or CONTENT_LENGTH is not
>> getting set. All the other CGI variables seem to be getting set
>> correctly.

>Try listing all env variables first to see what is there:

>#!/bin/sh
>echo Content-type: text/plain
>echo
>env

>If you append a proper query string to the URL (or GET method for a form)
>something should show up in QUERY_STRING.  For example using the above
>script with ?hello appended to the url, among env I see:

>QUERY_STRING=hello

>If you are trying to do POST method, then CONTENT_LENGTH is required
>because there is no other way to determine end of data (no newline or
>eof).  Looking through the Adv-Bash-Scr-HOWTO in Linux, 'read' would not
>work (no way to specify length), but possibly 'dd' which can read a
>specified number of bytes (default is from stdin).

>--
>David Efflandt  (Reply-To is valid)  http://www.de-srv.com/
>http://www.autox.chicago.il.us/  http://www.berniesfloral.net/
>http://cgi-help.virtualave.net/  http://hammer.prohosting.com/~cgi-wiz/

 
 
 

1. BASH BASH BASH BASH BASH BASH BASH BASH BASH BASH

Is there a proper fixed bash on any of the FTP sites out there?

I know there bash is on the usual sites but I don't know if they are
bugged or not :(

Regards,

Neil.

--


------------------------------------| Edinburgh, EH14 2DE, United Kingdom
**Domino: There`s nothing you can do when you`re the next in line: Domino**

2. Client-Server , problem using send(socket,...) command .

3. CGI-BIN sh script reading stdin??

4. Solaris 2.6: kernel mod

5. Bash calls TCL, TCL calls Bash, 2nd Bash never reads input

6. Intel Linux handling of multiple SCSI busses

7. Bash/CGI - - HTML call to Bash script

8. Mounting my CD-ROM

9. read from stdin while reading line by line a file

10. how to read http://localhost/cgi-bin/test-cgi??

11. /cgi-bin/phf /cgi-bin/test-cgi /cgi-bin/handler

12. empty STDIN in CGI POST

13. httpd/OSF/perl/CGI stdin pipe problem