Run your script with the command perl -wc script.cgi. This forces a compile with warnings. The warnings this script produces is: syntax error at deleteme.pl line 9, near "= ;"
I'm not going to offer any more help because you should easily be able to diagnose the issue for yourself from here. | [reply] [d/l] [select] |
When you get "500 Internal Server Error", you can usually find the cause of the problem in the server log files. There are a number of things that could cause this problem and some of them are platform dependent.
If you're using Apache on *nix, look for a file named error_log. If you're using Apache on Windows, it's probably error.log. For other servers, I don't know.
... Now I'll take a look at your code and let you know if I see anything significantly wrong. There might not be anything, though. You need the error message from that log file to tell you what's wrong.
--
-- GhodMode
Blessed is he who has found his work; let him ask no other blessedness.
-- Thomas Carlyle
| [reply] |
Since you can't run the script on the command-line (not sure why), and you most likely will get other syntax errors in the future, you might like to add near the top of your script (after the #! line):
use CGI::Carp qw(fatalsToBrowser);
This will send error messages to the browser so you can see them. You probably don't want that in production.
You error is that you need $num = ""; or just my $num;
| [reply] [d/l] |
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.
| [reply] [d/l] |
I understand that your ISP probably restricts the access you can have for CGI, probably for security reasons; lower end hosting packages tend to be like that. If you are able to afford it, I'd suggest looking into a package that gives you shell access, so you can run it from the command line.
If that is not an option for you, I'd suggest:
- you install perl on your PC. I assume you're running some version of Windows, in which case there are many different perl distributions available. I'm happy with and would recommend ActiveState Perl. You can then run the scripts on your PC to test with perl -wc your-script-name-here.pl from the command prompt, then upload it to the server. It obviously won't be the same thing as what they have on the server, but at least you don't have to keep asking to look at the logfile for trivial errors. (To get a command prompt, go to start->run->type cmd->click OK).
- Asking your hosting provider what perl modules they have available for you to use. One good one is Mail::Sendmail; a quick search on search.cpan.org also turns up others.
| [reply] [d/l] |
| [reply] |
If you are certain that the error logs you reported in one of your other replies above actually came from your script (rather than someone else's), then you must have made some changes that you haven't posted.
The posted code does not contain any logic to print a message like "failed to open log file"; if you now have a modified version of your script that includes this sort of message, that is what's causing that error message.
As for the logic that is posted, there are problems:
If I can guess correctly about what you are trying to do here, it might make more sense like this (though I have no way to know whether this will actually work for you):
#!/usr/bin/perl -w
use strict;
my $mailprog = '/usr/lib/sendmail';
my $mail = 'recipient-email@adress.com';
my $from = 'sender-email@address.com';
my $file = 'report.txt';
my $num;
if ($ENV{QUERY_STRING} ne "new" and -f $file) {
open (DATA, $file);
$num = <DATA>;
close (DATA);
$num =~ s/\D+//g;
}
$num ||= 0;
if ( open (MAIL, "|$mailprog -t")) {
print MAIL "Content-Type: text/plain; charset = windows - 1251\n";
print MAIL "Subject: Text, Text!\n";
print MAIL "To: $mail\n";
print MAIL "From: $from\n\n";
print MAIL "Hello, the message text itself..\n";
print MAIL "\n\n";
close (MAIL);
$num++;
} else {
$num = "Unable to use $mailprog";
}
if ( open (DATA, ">$file")) {
print DATA $num;
close (DATA);
} else {
my $might = ( -e $file ) ? 'does' : 'does not';
$num .= "<br>Unable to write to $file (it $might exist).";
}
print "Content-type: text/html\n\n";
print "$num\n";
That ignores most of the other advice about using CGI and FatalsToBrowser, etc, but if you have the right path for sendmail, it should work, and if you don't, it will tell you about that (sendmail is /usr/sbin/sendmail on the unix systems that I am familiar with).
Meanwhile, if there's a problem with opening the "report.txt" file for output, it will tell you about that, too; if you want it to report about not being able to open this file for input, you should be able to figure that out. If your ultimate goal is to send a set of emails to different people (or the same message to the same person a bunch of times), just add the appropriate loop around that middle "if/else" block. | [reply] [d/l] [select] |