#!/usr/bin/perl -w
$mailprog = '/usr/lib/sendmail';
$mail = 'recipient-email@adress.com';
$from = 'sender-email@address.com';
$file = 'report.txt';
$col = 2;
if (($ENV{QUERY_STRING} eq "new") && (-e $file)){unlink($file);}
open (DATA, $file);
$num = ;
close (DATA);
if ($num eq "") {$num = 0;}
for ($i = 1; $i<=$col; $i++){$n = $i + $num;
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);
}
open (DATA, ">$file");
print DATA $num+$col;
close (DATA);
print "Content-type: text/html\n\n";
print "$num\n";
print " \n";
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.
> use the scalpel to cut open the chest cavity
I'm not a doctor expert, what do you mean by "scalpel"?
line 8 - open (DATA, $file); line 9 - $num = ; line 10 - close (DATA);
Line 9 has a syntax error. The variable $num is not being assigned anything. The semicolon (';') tells Perl where the end of the statement is. Hence saying $num = doesn't mean anything to the compiler, because nothing is being assigned.
Its shared host, where NOT possible run command this way.
So test it on that machine you are sitting in front of. You'll get pretty tired of uploading, testing, uploading, testing pretty soon anyway. Install Perl if you don't have it already, and deal with at least all the syntax errors before uploading.
If you aren't familiar with Perl, then start by working with short contained scripts on a local machine, where you can see output and errors and learn to debug.
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.
-- -- GhodModeBlessed is he who has found his work; let him ask no other blessedness.
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.
It is quite easy to install ActiveState perl on Windows machines, and it would greatly improve your ability to test and learn perl.
Greetings, linex. I see that you have a surprisingly low XP balance for someone who has been a monk as long as you have. Reading over some of your previous posts, I notice that you seem to be characterized as someone who asks advice but then doesn't listen to the answers you receive. If you already have a firm idea fixed in your head, why do you keep asking questions?
You were advised in a previous comment to install Perl on your local PC so that you could troubleshoot problems with your script. This seems reasonable given the lack of control over the Unix environment from which you seem to be suffering. When you respond with this statement:
"Why I can no run script from command like? Because I have no perl installed on my PC."
... without following the advice you have already been given to install a local copy of the interpreter, you communicate an unwillingness to follow advice which makes me (and probably others) less willing to help you.
Here's some advice that is meant in a kindly way, in spite of the rebuking tone of this comment: when people offer help to your problems, at least pretend to follow or honor their advice.
You'll find a download for ActivePerl at this url: http://www.activestate.com/Products/ActivePerl/?mp=1.
Just glancing at your script, you should check the path to sendmail. I don't think that is the standard path.
Why I can no run script from command like? Because I have no perl installed on my PC.
Ok, this is the current state... now, any good reason not to install it?
At the very worst, why not getting an account on a machine on which Perl is installed or on which you could install it? Why not perlmonk?!?
If that is not an option for you, I'd suggest:
-- Burvil
Its a working machine, and its not mine, I do not own this machine, I can no install anything that not related to my job.
And this is only PC where I can test something, upload script, etc
Well, you would need to be logged on as an Administrator, i.e. be in the Administrators group, to do so. If you try to install it and it doesn't work, it may be very possible that you don't have administrative priveleges. I think I know where your employer is coming from - that they want to make sure that their network is secure and free from spyware, viruses and things like that, but Perl doesn't have those kinds of things.
So I just I intended ask small specific help. However, I do not expected that some Perlers are so aggressive, if not even more.. I do not know why. I never saw such aggressive help in other forums or newsgrops..
I don't know if it's so much that it's aggressive, but that having the right tools to do your job, and in this case to see what's wrong with your script, is crucial.
-- Burvil
Is this non installing Perl on a machine a crime?No, it isn't. But the only sane thing to do.
Its a working machine, and its not mine, I do not own this machine, I can no install anything that not related to my job.Maybe you could have mentioned this a bit earlier.
So I just I intended ask small specific help.You're asking for a trivial syntax error. On a typical coding day I make (and correct) way over 100 syntax errors. Imagine I (and others) would post them all.
I never saw such aggressive helpNobody is aggressive here. It's just we already have a bunch of monks who don't listen to what they have been told. Do you want to be among them?
perl yourscript.pl params for perl
You might temporarily add the path to perl to your PATH environment variable. Yes you can do that from the command line...
failed to open log file fopen: Permission denied [Wed Apr 5 10:27:59 2006] [error] [client IP] Premature end of script headers: /hsphere/local/home/domain/domain.com/cgi-bin/bmailer.cgi failed to open log file fopen: Permission denied [Wed Apr 5 10:28:04 2006] [error] [client IP] Premature end of script headers: /hsphere/local/home/domain/domain.com/cgi-bin/bmailer.cgi failed to open log file fopen: Permission denied [Wed Apr 5 10:28:07 2006] [error] [client IP] Premature end of script headers: /hsphere/local/home/domain/domain.com/cgi-bin/bmailer.cgi failed to open log file fopen: Permission denied [Wed Apr 5 10:28:16 2006] [error] [client IP] Premature end of script headers: /hsphere/local/home/domain/domain.com/cgi-bin/bmailer.cgiSo, dont know what is wrong in code if can no run even on normal hosting.
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.
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.
Cheers - L~R
In addition to the excellent advice you have already received about installing Perl on your work machine, you may also wish to look at the following alternatives:
Portable perl: usb thumbdrive
Never without (win32) perl
HTH,
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 (($ENV{QUERY_STRING} eq "new") && (-e $file)){unlink($file);}
That deletes the file. Once it is deleted, the script might not have permission to create it again (the "web user" account running the script would need write access on that directory, which might be a bad idea, or at least, might not be allowed).
#!/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 = ;
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 .= "
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.
perlmonks.org content © perlmonks.org and bart, blazar, bowei_99, cdarke, eric256, fishbot_v2, GhodMode, graff, holli, Limbic~Region, linex, marto, monarch, planetscape, ptum, xorl
prlmnks.org © 2006 edmund von der burg (eccles & toad)
v 0.03