LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 04-06-2004, 07:52 PM   #1
GridX
LQ Newbie
 
Registered: Sep 2003
Location: Canada
Distribution: Fedora & Gentoo-uClinux
Posts: 15

Rep: Reputation: 0
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
 
Old 04-06-2004, 07:59 PM   #2
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
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.
 
Old 04-06-2004, 08:00 PM   #3
leonscape
Senior Member
 
Registered: Aug 2003
Location: UK
Distribution: Debian SID / KDE 3.5
Posts: 2,313

Rep: Reputation: 47
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">
 
Old 04-07-2004, 01:37 AM   #4
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
Cool 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!
 
Old 04-07-2004, 08:34 AM   #5
GridX
LQ Newbie
 
Registered: Sep 2003
Location: Canada
Distribution: Fedora & Gentoo-uClinux
Posts: 15

Original Poster
Rep: Reputation: 0
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

Last edited by GridX; 04-07-2004 at 08:37 AM.
 
Old 04-07-2004, 10:37 AM   #6
prinski
LQ Newbie
 
Registered: Jul 2002
Posts: 7

Rep: Reputation: 0
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
 
Old 04-07-2004, 06:41 PM   #7
The_Nerd
Member
 
Registered: Aug 2002
Distribution: Debian
Posts: 540

Rep: Reputation: 32
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!
 
Old 04-12-2004, 11:01 PM   #8
GridX
LQ Newbie
 
Registered: Sep 2003
Location: Canada
Distribution: Fedora & Gentoo-uClinux
Posts: 15

Original Poster
Rep: Reputation: 0
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM
another cgi and shell scripting problem + webserver prinski Programming 6 04-08-2004 04:25 PM
shell scripting pcdebb Linux - Newbie 17 11-20-2003 03:49 PM
issue with shell cgi JustinHoMi Programming 0 11-07-2001 01:54 AM


All times are GMT -5. The time now is 07:14 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration