PDA

View Full Version : cgi newbie flouders, doesn't get perl


hilltopgo
1-5-02, 04:35 PM
Like so many before me, I'm having trouble getting a script to run. I've read through other messages, and can't figure out what I'm doing wrong -- path to perl is specified; script file is in a subdir of cgi-bin; chmode 755 on cgi-bin and the subdir; script uploaded in ascii mode; chmod to 755; HTML file is in htdocs, uploaded in ascii; added a .htaccess file (still didn't work) then deleted it (still doesn't work)... Argghh. Unless WS_FTP is goofing the chmod, i'm at a loss. But it reports '200 CHMOD command successful' so that must not be it. Server is pluto.

The script is a simple one I modified from BigNoseBird tutorial (http://www.bignosebird.com/prcgi.shtml) . (It also didn't work before I modified it.)
It is at hilltopgo.com/whywontitwork.txt (http://www.hilltopgo.com/whywontitwork.txt)

It didn't work when it was named .pl either.

I'm trying to post to it from a simple HTML file at
www.hilltopgo.com/myscript.html (http://www.hilltopgo.com/myscript.html) .

Here is the error message I've memorized from seeing it a hundred times:

=== begin http://www.hilltopgo.com/cgi-bin/myscript/myscript.cgi error message ===
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
[...]
More information about this error may be available in the server error log.


Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.

=== end http://www.hilltopgo.com/cgi-bin/myscript/myscript.cgi error message ===

Here is the error message from the error log file... rats! I deleted it, on the basis of a forum message that said deleting the error log and starting over seemed to help. (In my case, it didn't.) Now, even though I'm still getting the error, I see no error log. Egad, what are the permissions supposed to be for /logs/ ? I now have them set to 755; is that right? Life with no updated logs will be weird indeed.

Anyway, the error message was something quite close to this:

[Sat Jan 5 04:07:31 2002] [error] [client 206.103.67.249] Premature end of script headers: /www/h/hilltopgo/cgi-bin/myscript/myscript.cgi
Can't do setuid
[Sat Jan 5 04:07:31 2002] [error] [client 206.103.67.249] Premature end of script headers: /powweb/web/cgi-bin/error.cgi


Sorry for the length of this; i'm hoping to have it answered in one go, so didn't want to leave out a crucial clue. (Being a clueless newbie, i probably left it out anyway.)

Thanks for any help, - Mike the TacomaGoFiend

Bud
1-5-02, 06:04 PM
hi hilltopgo, I've been looking over the script and have a couple of questions.

At the top you have "=== begin '/cgi-bin/myscript/myscript.cgi' ===" - is this the first line in your script? Perl scripts should have the shebang (#!) and the path to Perl as the very first line.

#!/usr/bin/perl

Also, you are using "BEGIN" and "END" Perl subs in the script. They should be written in caps like BEGIN{print "something"}; and they should not be on the first line...I don't believe BEGIN or END subs are necessary in the script you are using, I would remove them.

Also, in the following (url decoding) ASCII substitution line:

$content=$s/%(..)/pack("c",hex($1))/ge;

There is a perl variable sign ($) before the substitution call (s/), I believe it should not be there.

It could be written like this:

$content=~s/%(..)/pack("c",hex($1))/ge;

Everything else looks good as far as I can see :)

~bud

hilltopgo
1-5-02, 08:01 PM
Hi Bud,

In the actual script file,
#!/usr/bin/perl
is the very first line.

The "=== begin '/cgi-bin/myscript/myscript.cgi' ===" and "=== end '/cgi-bin/myscript/myscript.cgi' ===" are not in the actual script file. They are only in the textfile that I posted.

Originally I posted the whole script in my plea for help, and i had those lines to mark the beginning and end of the script. (I guess my intent would have been more clear if I'd used ### instead of ===.) Then I read elsewhere that we should not post the whole script, but should just post a URL pointing to the script. So, I cut the script (with the now-unnecessary markers) out of the post, and put them in the "whywontthiswork.txt" file.

Sorry to cause confusion.

Thanks for helping, - Mike M.

hilltopgo
1-5-02, 08:04 PM
Hi again Bud,

You also discuss the line:
$content=$s/%(..)/pack("c",hex($1))/ge;

I see now that there is in fact an extra $
I'll remove it and see if that helps.

hilltopgo
1-5-02, 08:23 PM
Thanks for your help. I found some more typos i somehow introduced... shouldn't try to do this on no sleep. But it's working now. Thanks extremely much.

AND i magically have my error log back.

Now, i just have to figure out why my Simple Search script still pukes up a 500. - Mike M.

SimCoWeb
1-5-02, 09:58 PM
Hilltopgo, if you'll post the search script for download i'll check your configuration, do a test install on my own server and let you know what to do :)

hilltopgo
1-5-02, 10:32 PM
I thank you for your kindness. I have posted the script in its current incarnation at:
http://www.hilltopgo.com/search.pl.txt

I appended the .txt in case that makes a difference, since it's not in the cgi-bin directory. (It's named search.pl where i'm running it, from /cgi-bin/search/ )

The @files = line has several filenames in it, one of which is just a marker to help read the error log. Normally, I'll want to use wildcard instead of filenames, and it would look like this:
@files = ('*.txt','*.html','*.shtml');

Currently, it only needs to search *.txt, but I have hopes for the future. The files I want it to work on can be found linked from
http://www.hilltopgo.com/agej/

The error I'm getting now is
ls: 20011231.txt: No such file or directory
ls: 20011224.txt: No such file or directory
ls: 20011217.txt: No such file or directory
ls: 20011210.txt: No such file or directory
ls: 20011203.txt: No such file or directory
ls: *.txt: No such file or directory
ls: testmark.txt: No such file or directory

So somehow, i don't have the $basedir set correctly; but none of the permutations i've tried are working.

Best wishes, - Mike M.

hilltopgo
1-5-02, 10:34 PM
Sorry, forgot to mention -- the page that calls this script is:
http://www.hilltopgo.com/agej/search.html

SimCoWeb
1-5-02, 10:42 PM
The link you provided summons up a search results page. Can you post a link of upload for the script with all of your changes in it? Not the 'basic' script, but the one you've modified so I can see your paths and variables. Or, email it to me as an attachment at webmaster@simcoweb.com

hilltopgo
1-5-02, 11:24 PM
Thanks again...
Bizarre; it's executing the script from /htdocs/ even though it is now named 'search_orig.pl.txt', and the file permissions are 744. /htdocs/ permissions are 755. That's the correct chmod, isn't it? Is it normal for .txt files to execute as scripts? . I'll wrap it in <pre> tags and make it html. And make the permissions 644 instead of 744... seems legible now.

Anyway, hilltopgo.com/readme.html (http://www.hilltopgo.com/readme.html) has links to .txt files of the original and the modified script. Is that useful?

The (real) script will be at /cgi-bin/search/
The page that calls it will be at /htdocs/agej/
The .txt files to be searched are in /htdocs/agej/

Thanks muchly, - Mike M.

SimCoWeb
1-5-02, 11:38 PM
Your basedir path is incomplete:

/htdocs/agej/

should be:

/www/h/hilltopgo/htdocs/agej

That's assuming your username is 'hilltopgo'. Powweb sent you an email when you set up your hosting that shows you all of your base paths. Refer to that for the actual.

Also, even though you can run cgi scripts from anywhere on your server, it's best to set them up in the cgi-bin for security reasons. That keeps others from having access. You'd set it up like this:

/cgi-bin/search

Path would be:

/www/h/hilltopgo/cgi-bin/search

Or whatever you name the subdirectory.

If the script requires you to have separate directories for the HTML and the script then set the HTML directory in your /htdocs area (like you have it). Then under the $searchurl variable you'd have the URL to the search page (like you have it).

hilltopgo
1-5-02, 11:40 PM
YOU are gratifyingly fast. I will put the /h/... etc. into the path; thanks a bazillion!

hilltopgo
1-5-02, 11:46 PM
Success.

If you're ever in Seattle, let me know; I'll buy you a microbrew. Heck, i'll buy you a 6-pack.

Best wishes, - Mike M.

Bud
1-6-02, 04:13 PM
glad you got it all working hilltopgo :)

Just for future reference, if you delete your log file it'll be added back when the server reboots.

~bud

SimCoWeb
1-6-02, 08:07 PM
Thanks for the offer, hilltopgo. Perhaps i'll take you up on that someday. I've got family all over that area (Vashon Island, Snohomish, Bellevue, Bellingham, Anacortes, Lake Stevens), but, it rains too much for me :) So I live in a desert in SoCal.

Glad you got it working :)