LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-15-2006, 03:49 PM   #1
Tillus
Member
 
Registered: Dec 2004
Posts: 55

Rep: Reputation: 15
Question .cgi not executable


Hello

Do .cgi-files need to be compiled? My impression has been that writing the script (say in Perl) in f ex Kate should do the trick, but whatever I do the file is still represented by a screw-driver instead of a cog-wheel. The system calls it Perl-program instead of executable file and then I have changed the rights for the file and performed a
chmod a+x /pathway/echotest.cgi
I have also tried to copy the file to every cgi-bin on my computer without any results and the browser will list the contents of the scriptfile instead of running it (or is that the CGI passing it to the browser?) I know listing long scripts is not a favourable thing to do, but it's the only way I know for the moment, so here goes.

I'm running Red Hat 9.0

The script:

#!/usr/bin/perl
use CGI;
print CGI::header();
my %form_data = CGI::Vars;

print "Content-Type: text/html\n\n";
print "<HTML><HEAD><TITLE>";
print "Results for: ",$in{'name'};
print "</TITLE></HEAD><BODY>";
print "<H1>Just for You</H1>";
print "<P>Hi ",$in{'name'}," !\n";
print "<HR>";
print "<P>You live at ",$in{'address'};
print "<P><STRONG>Is this correct?</STRONG>";
print "<P>Homebrewer? Lessee...",$in{'hb'};
print "<P>You like homebrew!" if $in{'hb'} eq 'Yes';
print "</BODY></HTML>";

The latest link in the html doc:

FORM ACTION="file:/var/www/html/echotest.cgi" METHOD="post"

the .cgi-file and html code was saved in winsami2 encoding.


Last, but not least: A big thanks to "spooon" and "chrism01" for your answers to my earlier question on getting CGI up and running in the first place. You are life-savers.

Have I mentioned that the html code is wrtten with Kate too and works fine. So does the script as long as I'm running it from the Terminal, but it can't stop there, can it?


Lot of love
Tillus

Last edited by Tillus; 03-15-2006 at 05:06 PM.
 
Old 03-15-2006, 05:12 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
You do know you have to adjust the Apache httpd.config file for script aliases, so Apache (!) recognises it as executable?
WTF is winsami2 encoding ? What's wrong with good old ASCII text (for Perl anyway)?
 
Old 03-16-2006, 08:30 AM   #3
Tillus
Member
 
Registered: Dec 2004
Posts: 55

Original Poster
Rep: Reputation: 15
Nope, I don't know much at all. I've tried looking for some sort of apache for beginners, but have come up pretty short.

This is what my http.conf file says:

ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"

so I put the script above in this folder, but it still won't run. First I thought I might have to start apache first, so I typed

/sbin/service httpd start at the command-line.

It started, I tried again and still no difference. The CGI returns the script to the browser as a text-file instead of running it.


Tillus
 
Old 03-17-2006, 08:28 AM   #4
Spudley
Member
 
Registered: Mar 2003
Location: Berkshire, England.
Distribution: SuSE 10.0
Posts: 299

Rep: Reputation: 32
Quote:
Originally Posted by Tillus
The latest link in the html doc:

FORM ACTION="file:/var/www/html/echotest.cgi" METHOD="post"
I think I see your problem here.

By calling a "file:/" url, you're telling the computer to look for the link on the local filesystem, and not go via the web server. (I'm assuming you are running a web server? eg Apache)

You want to be accessing all your html pages and cgi scripts with addresses that start with something like "http://localhost/", rather than with "file:/".

So to access your main page (lets assume it's called 'page.html'), you'd enter "http://localhost/page.html" into your browser.

For best results, your links (eg the action=".." link) should also be relative links rather than fixed links, so if the cgi file is in the same directory as the html file (which it looks like it is from your example), you'd just write action="echotest.cgi".

Finally, Apache may need to be configured to run CGI scripts in the required directory (this may be disabled, depending on your current setup). If in doubt, use the cgi-bin folder that was there at the beginning.

I hope that helps.
 
Old 03-17-2006, 03:54 PM   #5
Tillus
Member
 
Registered: Dec 2004
Posts: 55

Original Poster
Rep: Reputation: 15
Yes, or at least I was running one. Only some file got lost all of a sudden (don't ask me how, it's pretty embarrassing) and I had to reinstall Linux. Now I have all sorts of files for Apache - even config programs - but I can't find Apache itself. Before the reinstallation there were HTML-files I could read on how to start it, but they seem to have gotten lost too. Does anyone know the command to start Apache from the terminal? All I can remember is /sbin/ something.

Could it be I have to reinstall it? I did tell Linux to throw in the webserver when I reinstalled, so it really has me puzzled. Or maybe I have to use another Installation type. As for the moment I'm running the type before Server-type that you'd want if your planning to do programming (Red Hat 9.0) if it helpes anyone. What doesn't make sence to me is why it would install half the program, but not all of it. Maybe the installation files are there if you know where to look? Does anyone?

Last question: Does anyone know of a way to reinstall without losing the user account?

Lots of love
Tillus
 
Old 03-17-2006, 04:55 PM   #6
Tillus
Member
 
Registered: Dec 2004
Posts: 55

Original Poster
Rep: Reputation: 15
Wonderful news on Apache. It turned out to be a documentation problem. After installing the doc-CDs I found the docs concerning turning apache on and off. A new problem arose though: I'm using this HTML-bit

FORM ACTION="http://localhost/var/www/cgi-bin/echotest.cgi" METHOD="post"

and I get a 404 Object not found on this server.

Does any one know how to get around this? The file exists and there are no spelling errors and the rights are set to executable for everyone.


Lots of thanks to the friendly souls that's helped so far, as well as future benefactors.
Tillus
 
Old 03-17-2006, 06:14 PM   #7
Spudley
Member
 
Registered: Mar 2003
Location: Berkshire, England.
Distribution: SuSE 10.0
Posts: 299

Rep: Reputation: 32
Quote:
FORM ACTION="http://localhost/var/www/cgi-bin/echotest.cgi" METHOD="post"
Drop the "/var/www" -- Folders in your web site are not the same as the folders in your actual file system.
 
Old 03-18-2006, 04:49 PM   #8
Tillus
Member
 
Registered: Dec 2004
Posts: 55

Original Poster
Rep: Reputation: 15
Thanks a lot! Now I actually get a response from the server! There is one thing I can't figure out though. I use the script from my first post, but the server only sends back the HTML-text. All the variables are left blank and when I try to look up the source for the returned dokument, the variables are missing there too, all of them. They aren't in the url (Query string) either. My question is: Can there be something syntactically wrong or is it as simple as turning some option on or off in the browser? With the risk of being long-winded I include the text between the FORM-tags in the HTML:

<FORM ACTION="http://localhost/cgi-bin/echotest.cgi" METHOD="post">
<P>Please enter your name: <INPUT TYPE="text" NAME="name" SIZE=40>
<P>E-mail address: <INPUT TYPE="text" NAME="email" SIZE=60">
<P>Mailing address: <TEXTAREA NAME="address" ROWS=5 COLS=45></TEXTAREA>
<P>Do you make homebrew?:
<INPUT TYPE="radio" NAME="hb" VALUE="Yes" CHECKED>Yes
<INPUT TYPE="radio" NAME="hb" VALUE="No">No
<P><INPUT TYPE="submit" VALUE="Send Info">

Also I can't decide on whether to use

#!/usr/local/cgi-bin/perl
require ("cgi-lib.pl");
&ReadParse;

which some people warn against as being dangerous even, or:

#!/usr/local/cgi-bin/perl
use CGI;

and maybe add

print CGI::header();
my %form_data = CGI::Vars;

Sorry for the long post. Special thanks to Spudley and all Chrism01 for your much needed assistance.
Love Tillus

Last edited by Tillus; 03-18-2006 at 04:50 PM.
 
Old 03-19-2006, 06:53 AM   #9
Tillus
Member
 
Registered: Dec 2004
Posts: 55

Original Poster
Rep: Reputation: 15
Smile

The problem with the variables was identified as a porting problem. The header

_________________should be changed to
#!/usr/bin/perl__________________________#!/usr/bin/perl
Require("cgi-lib.pl");_____________________use CGI;
&ReadParse;__________________________CGI::Readparse();

Thus porting it to the newest version of CGI.pm. Thank God for man-pages!

I do have one question though: How do you get linebreaks in the data echoed back from the script (f ex the line breaks in an address)? It is a bit tedious to get one long line for the address.


Thanks for all the help

Lots of love
Tillus

Last edited by Tillus; 03-19-2006 at 07:06 AM.
 
  


Reply



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
Perl CGI:Can't locate CGI.pm supermyself Programming 13 09-10-2007 06:22 AM
apache: using symbolic link to cgi-bin executable: how-to minutes2memories Linux - Software 4 03-02-2006 02:05 AM
Running a Java executable class from another executable class LUB997 Programming 22 07-24-2005 04:57 AM
CGI to work out side of cgi-bin? crashedspine Linux - Newbie 13 09-02-2004 08:49 PM
http://www.burstnet.com/cgi-bin/ads/ad7954a.cgi/3980/RETURN-CODE rverlander LQ Suggestions & Feedback 1 06-07-2002 07:35 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:00 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration