Solved

sh or bash cgi

Posted on 1997-12-21
4
616 Views
Last Modified: 2013-12-26
I'm designing a high school web page and i would like to add a student poll with 5 radio buttons.  I would like the cgi script to use a select case to determine which choice was not null.  I need help on the code for shell script, like how do i parse input from the html form like i can in Perl with the cgi-bin.pl library?  I need to be able to assign a varible to each 'name' element in the form. Please help me.  Thank you for your help.
0
Comment
Question by:alphamorgan
  • 2
4 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1295833
#!/bin/sh
echo Content-type: text/plain
echo
if [ "$REQUEST_METHOD"  =  "POST" ]
then
read QUERY_STRING
fi
case $QUERY_STRING in
*radio=button1*) echo button1 was selected;;
*radio=button2*) echo button2 was selected;;
*radio=button3*) echo button3 was selected;;
*radio=button4*) echo button4 was selected;;
*radio=button5*) echo button5 was selected;;
esac
for name in `echo $QUERY_STRING | tr '&' ' '`
do
echo $name
#this only works if your form variables are named like sh variables
eval $name
done
set
0
 
LVL 84

Expert Comment

by:ozo
ID: 1295834
But I should warn you that the
eval $name
could be dangerous if your script is called with something like
http://cgi.sh?/usr/bin/rm*.*
so you should really validate your input first.
0
 

Expert Comment

by:grantk
ID: 1295835
The biggest danger with CGI shell-scripting is the security.
Why can't you use perl with the -T option?
0
 

Accepted Solution

by:
mikal120797 earned 100 total points
ID: 1295836
You should be able to find all the sample scripts that you need, as well as possibly one to do just what you want (why reinvent the wheel?) at the following URL:

http://www.yahoo.com/Computers_and_Internet/Internet/World_Wide_Web/CGI___Common_Gateway_Interface/
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Host to IP 7 78
Add content to output file 4 63
move a line in eclipse 3 102
Excel file not created as expected 7 72
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question