LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   cgi and shell scripting, setting it up? (https://www.linuxquestions.org/questions/programming-9/cgi-and-shell-scripting-setting-it-up-167075/)

GridX 04-06-2004 07:52 PM

cgi and shell scripting, setting it up?
 
I have never programmed cgi scripts before, but I have done shell scripting and c++, and c programming.

My question is this. I want to creat a check box form( in html or cgi)

then hit submit and it will take me to a server hosted on a NETdimm.

so if I hit yes on the check box it will take me to the cgi script and in there the script will execute a c program that will run a function on the board.

I need to use cgi as its the only thing that will interface with my uclinux boa web server.


I am a little confused as to how to go about setting this up,

can I create the form entirely with html and then when I hit submit it will take me to the /cgi-bin/myprogram.cgi..... or can I do the entire web page in the cgi script. I am confused as to how this works.
how to test( dont have the boa web server setup yet)

some good links to cgi tutorials, and sample scripts(only in shell scripting/ perl not supported)


GridX

The_Nerd 04-06-2004 07:59 PM

All cgi is, is a program (written in any language) that prints html tags to stdout and receives input through enviroment variables. I have a CGI library that I wrote (it's C++) that makes writing CGI scripts REALLY easy.
I will e-mail it to you, or post a link here (so, just incase any body else want to use it they can). But as I always say: I am not responsible in any way for any damage caused by any of my code, though you may use it as you wish (unless I specify otherwise). I will post the link as soon as posible.

leonscape 04-06-2004 08:00 PM

A good resource is CGI Resource Index, also for more details is the CGI Documentation.

THe trick is to set up the form in HTML, Then input from the form will be recieved by the program through env vars and you output to stdout which will be recieved by the browser as an HTML document or redirection.

To set the form to execute the cgi when the user hits submit is part of the form tag. i.e

Code:

<FORM ACTION="http://www.mydomain.com/cgi-bin/exam.cgi" METHOD="POST">

The_Nerd 04-07-2004 01:37 AM

Done!!!
 
Well! I am finally done! Sorry, I didn't think it would take that long! I had to write documentation for using my library. It is included in the archive. You can download that here:

http://www.restorides.com/~nerd/libc...cgi-1.0.tar.gz

I hope you, and who ever else uses this library enjoys it.

You may use my code however you see fit. However I am not responsible in anyway for any damage caused by my code in any shape or form.

Oh! Also, if/when you are done with your CGI script(s) (who ever uses my library) I would appreciate it if you e-mailed me with the link, so I can go see it! Thanks! Enjoy!

GridX 04-07-2004 08:34 AM

Hey, thankyou, that helps alot. ( I havent read the documentation yet)

I have a few other questions, How can I test the cgi on my own computer...that is how do I set up a server on one computer to test the scripts and html, either in windows or linux( I work with both alot) can I use httpd in linux ? what about windows

also: I went to some other sites with cgi tutorials and they list environment variables : $query string etc...... they were like this:

now do I have to type or code all of these variables?

Code:

AUTH_TYPE        []
CONTENT_LENGTH    []
CONTENT_TYPE      []
GATEWAY_INTERFACE CGI/1.1
HOSTTYPE          []
HTTP_ACCEPT      image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
HTTP_CONNECTION  Keep-Alive
HTTP_HOST        cmis.mis.brighton.ac.uk
HTTP_PRAGMA      []
HTTP_REFERER      http://snowwhite.it.brighton.ac.uk/~.../try_for3.html
HTTP_USER_AGENT  Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)
OSTYPE            []
PATH_INFO        []
PATH_TRANSLATED  []
QUERY_STRING      page=mas&file=w:\\cgi-bin\\mas\\00mas_logs
REMOTE_ADDR      199.185.53.115
REMOTE_HOST      []
REMOTE_IDENT      []
REMOTE_USER      []
REQUEST_METHOD    GET
SCRIPT_NAME      /cgi-bin/mas/mas_rec
SERVER_NAME      www.cmis.brighton.ac.uk
SERVER_PORT      80
SERVER_PROTOCOL  HTTP/1.1
SERVER_SOFTWARE  Apache/1.3.20 (Win32) DAV/1.0.3-dev

Unix command pwd
/cygdrive/w/cgi-bin/mas
Unix command ps
Unix command printenv

Unix command set


COMSPEC=C:\WINNT\system32\cmd.exe
DOCUMENT_ROOT=w:/inetpub/wwwroot
GATEWAY_INTERFACE=CGI/1.1
HOME=/
HTTP_ACCEPT_ENCODING=gzip, deflate
HTTP_ACCEPT_LANGUAGE=en-us
HTTP_ACCEPT=image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*
HTTP_CONNECTION=Keep-Alive
HTTP_HOST=cmis.mis.brighton.ac.uk
HTTP_REFERER=http://snowwhite.it.brighton.ac.uk/~mas/mas/courses/html/try_for3.html
HTTP_USER_AGENT=Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)
IFS=       
LOGONSERVER=\\IT-STAFF
PATH=/bin:/oracle/ora81/bin:/Program Kit/
PS1=$
PS2=>
QUERY_STRING=page=mas&file=w:\\cgi-bin\\mas\\00mas_logs
REMOTE_ADDR=199.185.53.115
REMOTE_PORT=3179
REQUEST_METHOD=GET
REQUEST_URI=/cgi-bin/mas/mas_rec?page=mas&file=w:\\cgi-bin\\mas\\00mas_logs
SCRIPT_FILENAME=w:/cgi-bin/mas/mas_rec.EXE
SCRIPT_NAME=/cgi-bin/mas/mas_rec
SERVER_ADDR=193.62.183.2
SERVER_ADMIN=cmiswebmaster@bton.ac.uk;cc17@bton.ac.uk
SERVER_NAME=www.cmis.brighton.ac.uk
SERVER_PORT=80
SERVER_PROTOCOL=HTTP/1.1
SERVER_SIGNATURE=Apache/1.3.20 Server at www.cmis. Port 80
SERVER_SOFTWARE=Apache/1.3.20 (Win32) DAV/1.0.3-dev
SYSTEMROOT=C:\WINNT
TERM=cygwin
TZ=GMTST0GMTDT-1,M3.5.0/1,M10.5.0/2
WINDIR=C:\WINNT


prinski 04-07-2004 10:37 AM

hi
 
i'm also learning this.

what i have done is install apache (in linux that was), then you have to configure cgi as described here: http://httpd.apache.org/docs/howto/cgi.html

they also described how to test it i think. For myself i wrote some small shell commandos in a script and tested it. Oh yeah, for input from html forms to cgi i used proccgi.sh (you find it on google or other search machines).
I got it working in no time

greets,

prinski

The_Nerd 04-07-2004 06:41 PM

Well I have RedHat 9.0, and it comes installed with Apache. So all I have to do is compile my cgi script, and copy it to /var/www/cgi-bin, then (after starting Apache... wich is done like this: "httpd" as super user) I open my fav' browser, and type: http://127.0.0.1/cgi-bin/myscript.cgi

Thats all there is to it!

GridX 04-12-2004 11:01 PM

can I save the my .cgi as a .sh? or can I write the script in unix shell or C programming and save it as .cgi?

what script is saved as .cgi?

the shell script?

GridX


All times are GMT -5. The time now is 04:19 AM.