in reply to I'm getting a 500 Internal Server Error - how can I make this work?

linex,
First, you really should verify that this program compiles before attempting to run it. I know you have said that you don't have perl installed locally but it is freely available on almost every platform. See TinyPerl if you want to run it from a floppy disk or other external media.

Second, I find it hard to believe you can delete files on this host but that you can't create any. On most systems, your home directory or the /tmp directory is writeable by you. If you truly can't create any files anywhere then your script is never going to work because your own code is creating a file.

Third, CGI::Carp can't display compile time errors to the browser without a little help. For that you would need to bypass the web server log. See this for details. It assumes that you really can create a file.

Fourth, you should still be able to validate that the script compiles even if you don't have perl locally or a shell account on the host. Create a new script that executes a system call to perl -wc of the first script. Since you are unlinking files and opening pipes to external mail programs - I don't see why this wouldn't work.

I do hope that you can get things to work. If none of these other pieces of information are helpful then try a completely different approach. Start out with a working script that doesn't nothing more than prints "hello, world" to the browser screen. Next add on a single bit of information and test it. Continue this process until you find exactly what the problem is or you get a working solution.

Update:
I have taken the liberty of re-writing your code to something I know compiles and corrects some of the logic problems of your own. I say some because you have a race condition that you will have to address on your own if it is a real issue. Use this at your own risk as it comes with no guarantees.

#!/usr/bin/perl use strict; use warnings; use CGI qw/:standard/; use CGI::Carp qw(fatalsToBrowser); my $prog = '/usr/lib/sendmail'; my $to = 'Foo@nowhere.com'; my $from = 'Bar@somewhere.com'; my $file = 'report.txt'; my $num = 0; if ($ENV{QUERY_STRING} eq 'new' && -e $file) { unlink $file or die "Unable to remove '$file': $!"; } else { open(my $fh, '<', $file) or die "Unable to open '$file' for readin +g: $!"; $num = <$fh>; chomp $num; } my ($col, $n) = (2, 0); for my $i (1 .. $col) { $n = $i + $num; open (my $mail, '|-', $prog) or die "Unable to open a pipe to '$pr +og': $!"; gen_message($mail, $to, $from); } open(my $fh, '<', $file) or die "Unable to open '$file' for writing: $ +!"; print $fh $num + $col; close $fh; print header, start_html($num), $num, end_html(); sub gen_message { my ($mail, $to, $from) = @_; print $mail "Content-Type: text/plain; charset = windows - 1251\n" +; print $mail "Subject: Text, Text!\n"; print $mail "To: $to\n"; print $mail "From: $from\n\n"; print $mail "Hello, the message text itself..\n"; print $mail "\n\n"; }

Cheers - L~R

  • Comment on Re: I'm getting a 500 Internal Server Error - how can I make this work?
  • Download Code