CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
problem accessing perl script

 



Larkdog
User

Feb 16, 2005, 7:30 PM

Post #1 of 14 (1962 views)
problem accessing perl script Can't Post

hello, i have a script that runs flawlessly from the command line and a web server. but it won't work at all on another server. the server that works runs perl 5.06?? and the new runs perl 5.08?? the cgi-bin is chMOD 755 and so are the files...the web browser only gives the 500 error, but the error log file shows 3 errors:

failed to open log file

fopen: Permission denied

Premature end of script headers

what could I have missed?

I called tech support and they danced around the problem but never gave a solution. What do you guys think? What else could I post here to help you diagnose?

On the old server, I had to start the scripts using #!perl/bin/perl, but that wouldn't work on the new server, and neither would #!usr/bin/perl so I am frustrated!Unsure
www.MrLarkins.com


davorg
Thaumaturge / Moderator

Feb 17, 2005, 1:52 AM

Post #2 of 14 (1960 views)
Re: [Larkdog] problem accessing perl script [In reply to] Can't Post


In Reply To
On the old server, I had to start the scripts using #!perl/bin/perl, but that wouldn't work on the new server, and neither would #!usr/bin/perl so I am frustrated!Unsure


Well, even the least clued up technical support person should be able to tell you what the path to Perl is on their server. I'd guess it will probably be #!/usr/bin/perl or #!/usr/local/bin/perl - the slash at the start of the path (which you omitted) is vitally important.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Larkdog
User

Feb 17, 2005, 5:06 AM

Post #3 of 14 (1957 views)
Re: [davorg] problem accessing perl script [In reply to] Can't Post

thanks for noticing my typo...lol yea, the slash is there in the code, i just was typing to fast in this forum...and the tech person said the path to Perl was #!/usr/bin/perl , but it never would work, just gave us those 3 error messages in the error log file... I also tried #!/usr/local/bin/perl and that didn't work either AND I got the same three error message in the error log file...

the 'tech' support person never said much except umm, ohh, and that's weird.

i did do a "hello, world" test and it work! http://www.mrlarkins.com/cgi-bin/hello.pl

this is the beginning of my script:

Code
  

#!/usr/bin/perl

use strict;

use CGI;

use CGI::Carp qw(fatalsToBrowser);




and here is the "hello, world" that works:

Code
  

#!/usr/bin/perl

print "Content-type: text/html\n\n";

print "Hello, World";





still confused here
www.MrLarkins.com


davorg
Thaumaturge / Moderator

Feb 17, 2005, 5:37 AM

Post #4 of 14 (1955 views)
Re: [Larkdog] problem accessing perl script [In reply to] Can't Post


In Reply To
failed to open log file


Is that an error message that's generated from your program? Perhaps the paths to various files that your program tries to open aren't the same on the new server. Or perhaps you don't have permissions to read some of the files you want.

What happens when you run the program from the command line on the new server?

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Larkdog
User

Feb 17, 2005, 10:18 AM

Post #5 of 14 (1946 views)
Re: [davorg] problem accessing perl script [In reply to] Can't Post

ok, my script does not try to open or create any file...it simply takes text that was input in a form and through a 'secret' process converts each letter to a different letter, thus encrypting the original text...

here it is:


Code
    

#!/usr/bin/perl

use strict;

use warnings;

use CGI;

use CGI::Carp qw(fatalsToBrowser);

my %code_hash = (

a => 1, b => 2, c => 3, d => 4, e => 5, f => 6, g => 7, h => 8, i => 9, j => 10, k => 11,
l => 12, m => 13, n => 14, o => 15, p => 16, q => 17, r => 18, s => 19, t => 20, u => 21, v => 22, w => 23, x => 24, y => 25, z => 26, '+' => 27, '.' => 28, '?' => 29, '!' => 30, '@' => 31);

my %decode_hash = (

1 => 'a', 2 => 'b', 3 => 'c', 4 => 'd', 5 => 'e', 6 => 'f', 7 => 'g', 8 => 'h', 9 => 'i', 10 =>
'j', 11 => 'k', 12 => 'l', 13 => 'm', 14 => 'n', 15 => 'o', 16 => 'p', 17 => 'q', 18 => 'r', 19 => 's', 20 => 't', 21 => 'u', 22 => 'v', 23 => 'w', 24 => 'x', 25 => 'y', 26 => 'z', 27 => '_', 28 => '.', 29 => '?', 30 => '!', 31 => '@');

my $q1 = new CGI;

print $q1->header;

my $message = $q1->param('message');

my @message = &encode($message);

sub encode {

my $message = shift;

$message = lc $message;

$message =~ s/[^a-zA-Z\.\?\_\!\@\s]//g; #get rid of unwanted characters

$message =~ s/\s+/\+/g; #substitute + for spaces

my @temp = split(//,$message); #split characters into @temp array

s/\Q$_\E/$code_hash{$_}/gi for @temp; #convert message to code

return(@temp); #return results

}

my $count;

my $remainder;

$count = @message;

$remainder = $count % 3;

while ($remainder == 1 || $remainder == 2) {

push @message,'27';

$count = @message;

$remainder = $count % 3;

};

my @code;

@code = (0,1,0,1,1,0,1,0,1);

my $n1;

my $p1;

my @coded_message;

$n1 = 0;

$p1 = 0;

until ($n1 == $count){



$coded_message[$p1] = ($code[0] * $message[$n1++]) + ($code[1] * $message[$n1++]) +
($code[2] * $message[$n1++]);

$p1+=3;

}

$n1 = 0;

$p1 = 1;

until ($n1 == $count){

$coded_message[$p1] = ($code[3] * $message[$n1++]) + ($code[4] * $message[$n1++]) +
($code[5] * $message[$n1++]);

$p1+=3;

}

$n1 = 0;

$p1 = 2;

until ($n1 == $count){

$coded_message[$p1] = ($code[6] * $message[$n1++]) + ($code[7] * $message[$n1++]) +
($code[8] * $message[$n1++]);

$p1+=3;

}

$n1 = 0;

until ($n1 == $count) {

until ($coded_message[$n1] < 32){

$coded_message[$n1] = $coded_message[$n1] - 31;

}

$n1++;

}

$n1 = 0;

until ($n1 == $count) {

until ($coded_message[$n1] > 0) {

$coded_message[$n1] = $coded_message[$n1] + 31;

}

$n1++;

}



@coded_message = &decode(@coded_message);

sub decode {

s/\Q$_\E/$decode_hash{$_}/gi for @coded_message;



return (@coded_message);

}

{

local $" = '';

print <<EOF

<HTML>

<HEAD>

<TITLE>Encrypted Message!</TITLE>

</HEAD>

<BODY><center>

<H1>Your message has been encrypted\!</H1>

<p>Your message has been successfully encrypted.<BR><font color=orange size=4><b>
@coded_message</b></font></p></center>

</BODY>

</HTML>

EOF

}



as you can see, it is just supposed to output the new text to the browser. and as for running it from the command line on the new server, i assume it worked b/c the tech person did that as said 'well it worked here' but i didn't actually do it myself...maybe i should do that
www.MrLarkins.com

(This post was
edited by Larkdog on Feb 17, 2005, 4:35 PM)


KevinR
Veteran


Feb 17, 2005, 1:49 PM

Post #6 of 14 (1940 views)
Re: [Larkdog] problem accessing perl script [In reply to] Can't Post

Hey, it's Mr. Larking with the secret code script! Cool

All I can think to say is...umm, err, weird! Crazy

Sly
-------------------------------------------------


Larkdog
User

Feb 17, 2005, 4:19 PM

Post #7 of 14 (1934 views)
Re: [KevinR] problem accessing perl script [In reply to] Can't Post

hey kevin! i do remember all your help on these scripts, but now i can't use them! you got any suggestions???
www.MrLarkins.com


KevinR
Veteran


Feb 17, 2005, 6:44 PM

Post #8 of 14 (1928 views)
Re: [Larkdog] problem accessing perl script [In reply to] Can't Post


In Reply To
hey kevin! i do remember all your help on these scripts, but now i can't use them! you got any suggestions???


I wish I did have some suggestions for you. Are you sure that script is producing those lines in the log/error file? They don't seem to have anything to do with that script. What's the hosting service you are using?
-------------------------------------------------


Larkdog
User

Feb 17, 2005, 8:09 PM

Post #9 of 14 (1927 views)
Re: [KevinR] problem accessing perl script [In reply to] Can't Post

the scripts are definitely causing the error, b/c after each error it says 'referrer: cryptology.html' which is the form that calls the scripts
www.MrLarkins.com


KevinR
Veteran


Feb 17, 2005, 11:14 PM

Post #10 of 14 (1925 views)
Re: [Larkdog] problem accessing perl script [In reply to] Can't Post

Are you sure you uploaded the scripts in ASCII (text) format and not binary?
-------------------------------------------------


davorg
Thaumaturge / Moderator

Feb 18, 2005, 2:39 AM

Post #11 of 14 (1918 views)
Re: [Larkdog] problem accessing perl script [In reply to] Can't Post

The "permission denied" error may well be some kind of suexec problem. Are your new hosting company running some kind of suexec or suidperl setup?

What are the permissions on the cgi program? Some suexec installations get upset if they are too liberal. Try changing them to 755.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Larkdog
User

Feb 18, 2005, 5:06 AM

Post #12 of 14 (1915 views)
Re: [KevinR] problem accessing perl script [In reply to] Can't Post


In Reply To
Are you sure you uploaded the scripts in ASCII (text) format and not binary?



you are brilliant! that was it! can you tell me why it makes a difference? i know the difference between ASCII and binary (i think), but why does it affect the scripts? how does it alter the file during transfer?
www.MrLarkins.com


davorg
Thaumaturge / Moderator

Feb 21, 2005, 4:26 AM

Post #13 of 14 (1908 views)
Re: [Larkdog] problem accessing perl script [In reply to] Can't Post


In Reply To
can you tell me why it makes a difference? i know the difference between ASCII and binary (i think), but why does it affect the scripts? how does it alter the file during transfer?


I'm guessing you're uploading from a Windows machine to a Unix machine.

This article explains the problem in some detail.

As to why is causes a problem. Perl is quite capable of running code that has the extra ^M on the end of each line, but the problem is with the shebang line. Unix isn't quite as clever as Perl and gets confused when looking for a progam called /usr/bin/perl^M.

--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


Larkdog
User

Feb 21, 2005, 5:25 AM

Post #14 of 14 (1907 views)
Re: [davorg] problem accessing perl script [In reply to] Can't Post

oh! that explains a lot! what still baffles me is the ignorance of my host company! guess i might want to educate them...thanks guys!
www.MrLarkins.com

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives