500 Internal Server Error with perl script

Status
Not open for further replies.

erko1

New Member
Messages
4
Reaction score
0
Points
0
Hi,

I get the 500 Internal Server Error when trying to use any perl script.

I looked through other similar posts but did not find any solution. My address for the a test script is http://ea.exofire.net/cgi-bin/test.cgi. Code for the script is:

#!/usr/bin/perl -w
print "Content-type: text/plain\r\n";
print "Hello World";

The file is chmod 755 and uploaded using ascii. I do not know what else should I do. There is no information in the error log either.

Thanks for any help.

Erko
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
have you tried changing the file extension to *.pl ?
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
hmm... try this script

Code:
#!/usr/bin/perl -w
my ($w,$x,$y) = ($ENV{'REMOTE_ADDR'},$ENV{'REMOTE_HOST'},$ENV{'HTTP_REFERER'});

use ExtUtils::Installed;
use Sys::Hostname;
use Net::Domain qw(hostname hostfqdn hostdomain);
use Socket;


my $inst    = ExtUtils::Installed->new() or &error('1',"Couldn't get modules");
my @modules = $inst->modules() or &error('2',"Couldn't get modules");


my $h_name = hostname();
my $d_name = hostfqdn();


my $address1 = inet_ntoa(
  scalar gethostbyname( $h_name || 'localhost' )
  );
my $address2 = inet_ntoa(
  scalar gethostbyname( $d_name || 'localhost' )
  );

&print_html;

sub print_html { 
print "Content-type: text/html\n\n" or &error('3',"Couldn't print Header");;
print <<ENDHTML or &error('4',"Couldn't print to HTML");
<HTML>
<HEAD>
<TITLE>Perl Module Test</TITLE>
</HEAD>
<BODY>
These are all the modules installed on this server!\n
ENDHTML
foreach (@modules) {
print "$_\n";
print "<P>\n" or &error('5',"Couldn't print modules");
}
print "Your IP: $w\n<br>";
print "Where you just came from : $y\n<br>";
print <<ENDHTML
This is the host name : $h_name : $address1
<br>
This is the domain name : $d_name : $address2
</BODY>
</HTML>

ENDHTML

}

sub error {
my ($no,$reas) = @_;	
	print "Error, $no\n<br>";
	print "$reas\n<br>";
}
chkmod to 755 and place in cgi-bin.
 

erko1

New Member
Messages
4
Reaction score
0
Points
0
Thank you, I got this script working now. Your script worked well immediately (http://ea.exofire.net/cgi-bin/longTest.pl).

I compared your script with mine and found a small mistake. My correct code should be:
Code:
 #!/usr/bin/perl -w
print "Content-type: text/plain\n\n";
print "Hello World";

Previously the second line was:
Code:
 print "Content-type: text/plain\r\n";

So this is solved now. Thanks again!
 

DefecTalisman

Community Advocate
Community Support
Messages
4,148
Reaction score
5
Points
38
Its a pleasure. Thought the new line could have been a problem, but haven't used Perl in so long now and PHP kinda corrupted me.
 
Status
Not open for further replies.
Top