LinuxQuestions.org
Register a domain and help support LQ
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-07-2004, 07:13 AM   #1
prinski
LQ Newbie
 
Registered: Jul 2002
Posts: 7

Rep: Reputation: 0
another cgi and shell scripting problem + webserver


Hi everyone,

can someone give me some information about this...
what i'm trying to do is: i put up a webserver with a form on the webpage for filling in your name. When submitting that, i would like to run a cgi script with the given name as input in linux shell commandos that looks up your ID. Then i'd like to show that ID on the webpage.


How do i do that? i have created a form and the script. I googled a bit but couldn't find out how to give the ID back and put it in html.

Also, how do i use the given name in the script? e.g. when the form has <input type="text" id="yourname">, do i have to use $yourname?



hope someone can help me

greets,

prinski
 
Old 04-07-2004, 12:22 PM   #2
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
What exactly are you trying to do with shell scripting? I'm not sure I understand that part.

What sort of ID are you looking up? Where is it stored?
 
Old 04-07-2004, 04:57 PM   #3
nerdstat
LQ Newbie
 
Registered: Apr 2004
Location: Brussels, Belgium
Distribution: Gentoo with 2.6.8-kernel
Posts: 15

Rep: Reputation: 0
I believe this piece of shell-code will answer your questions. Simply copy/paste it and put it on your webserver:

#!/bin/sh

# disable filename globbing
set -f

echo Content-type: text/html
echo

echo CGI/1.0 test script report:
echo

echo argc is $#. argv is "$*".
echo

echo SERVER_SOFTWARE = $SERVER_SOFTWARE
echo SERVER_NAME = $SERVER_NAME
echo GATEWAY_INTERFACE = $GATEWAY_INTERFACE
echo SERVER_PROTOCOL = $SERVER_PROTOCOL
echo SERVER_PORT = $SERVER_PORT
echo REQUEST_METHOD = $REQUEST_METHOD
echo HTTP_ACCEPT = "$HTTP_ACCEPT"
echo PATH_INFO = "$PATH_INFO"
echo PATH_TRANSLATED = "$PATH_TRANSLATED"
echo SCRIPT_NAME = "$SCRIPT_NAME"
echo QUERY_STRING = "$QUERY_STRING"
echo REMOTE_HOST = $REMOTE_HOST
echo REMOTE_ADDR = $REMOTE_ADDR
echo REMOTE_USER = $REMOTE_USER
echo AUTH_TYPE = $AUTH_TYPE
echo CONTENT_TYPE = $CONTENT_TYPE
echo CONTENT_LENGTH = $CONTENT_LENGTH


Experiment a bit with it and have fun !!
 
Old 04-07-2004, 05:27 PM   #4
prinski
LQ Newbie
 
Registered: Jul 2002
Posts: 7

Original Poster
Rep: Reputation: 0
hello again

hi,
thanx for replying both.

i learned a lot of cgi and shell scripting today myself :-)
david, i will explain a bit more. i have a webserver with cgi running. When a client enters his hostname, id and password in a form on the website, the webserver (being front end of a dns server) updates some configuration files and also updates the webserver.
I kinda find out today how to get it fixed.

But i still have some shell scripting problems:
1. i can type in the command: cat /myfile | grep $FORM_hostname | cut -d" " -f4
which means i have a file with records in it in the form of (hostname ipaddress id otherinfo) and i want to check the <otherinfo> belonging to some hostname the user gave as input. that <otherinfo> is the info the webserver will show to the browser.
But i cannot put this in my shell scripting file, it gives errors. How can i echo this <otherinfo>? it must be possible ..

2. there are some others, but i'm not at home right now and can't come up immediately with them.
 
Old 04-08-2004, 01:36 AM   #5
nerdstat
LQ Newbie
 
Registered: Apr 2004
Location: Brussels, Belgium
Distribution: Gentoo with 2.6.8-kernel
Posts: 15

Rep: Reputation: 0
What are the other errors? I know that when I used CGI, that I had some problems with the PATH. The CGI-program was not always executed where is was located.
Perhaps you should try to use absolute paths to the files.
 
Old 04-08-2004, 12:12 PM   #6
david_ross
Moderator
 
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 64
What are you using to retrieve the information sent to your script? It may be easier in perl and the CGI module. Perhaps you could post your script.
 
Old 04-08-2004, 04:25 PM   #7
prinski
LQ Newbie
 
Registered: Jul 2002
Posts: 7

Original Poster
Rep: Reputation: 0
new questions

i should probably have picked perl indeed :-)
although i have some knowledge of perl i choose something new for me: cgi with shell scripting.
suprisingly retrieving the data from the input (a form) is simple if you use proccgi (i downloaded the proccgi.sh script and it works great).

but concerning shell scripting i have some new questions!:

1. im using /bin/sh. Now i have the following problem: in a while loop (while read LINE) I want to save the right line in a variable (so for one specific LINE : rightLine=$LINE ). Now i have to use $rightline later on, but this is not possible because rightline is a local variable of the loop. I dont know what to do now, i have to use the right line later in my script. Does someone know workarounds for this?

2. how to make files in a cgi script. I always get 'permission denied'. My script needs -rwxrwxrwx. A solution might be to make the file also -rwxrwxrwx (im not sure), but if this works, how can i do that. In commands: i want: echo "foo" > myFile.log (this gives me the permission denied error).

2.1 a similar problem is that i want to read information from a file which is -rwx------ or so. when i want to read information from such a file and write it in another one with probably less permissions i get this error.

2.2 another one is: i want to execute the ipsec command from a script: 'ipsec auto --add myConnection'. But this seems to be a command that only root may do. How to solve this.

The problem that always comes back is that i think that a cgi-script runs as a normal user and not as root. Is it possible to let the cgi script run as root?

3. what command can i use for testing whether a string is contained in some other string. I want to use it like this:
if [ "lo" in "hello everyone" ] //i dont know a command to do this in the shell
then ...
fi

who can tell me what the if-condition must look like?
greets,

prinski

Last edited by prinski; 04-08-2004 at 04:35 PM.
 
  


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 problem for importing Firefox files montylee Programming 6 06-03-2005 01:52 AM
shell scripting: variable problem XST1 Programming 7 01-30-2005 01:45 PM
cgi and shell scripting, setting it up? GridX Programming 7 04-12-2004 11:01 PM
Shell Scripting Problem linuxboy69 Linux - Software 2 03-31-2004 07:36 PM
problem in shell scripting visu Linux - Newbie 4 01-06-2004 04:16 PM


All times are GMT -5. The time now is 02:41 PM.

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