where need be corrected to make script work?
linex
created: 2006-04-05 07:27:23
Hi,
can no get the script work, get 500 'Internal Server Error'
The question is what and where need be corrected to make script work? (question is not is this code designed good or bad. Just make script to work.)
#!/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";

Re: where need be corrected to make script work?
created: 2006-04-05 07:39:42
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.

Re^2: where need be corrected to make script work?
created: 2006-04-05 08:00:45
>"Run your script with the command perl -wc script.cgi"

I canno do this. Its shared host, where NOT possible run command this way.

"syntax error at deleteme.pl line 9, near "= ;"

Since i am not a perl expert, i'm not well with perl syntax..
So how it should be correctly?
Re^3: where need be corrected to make script work?
created: 2006-04-05 08:21:10
Hi, I have been scheduled to perform surgery on Mr Unlucky in Operating Room 3.

> use the scalpel to cut open the chest cavity

I'm not a doctor expert, what do you mean by "scalpel"?

Re^3: where need be corrected to make script work?
created: 2006-04-05 08:25:45
Your code is
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.

Re^3: where need be corrected to make script work?
created: 2006-04-05 09:05:57
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.

Re: where need be corrected to make script work?
created: 2006-04-05 07:40:53

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
Re: where need be corrected to make script work?
created: 2006-04-05 08:28:47
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;
Re^2: where need be corrected to make script work?
created: 2006-04-05 08:58:01
Why I can no run script from command like? Because I have no perl installed on my PC.

I use shared host for testing purposes, that does not offer log files.

I corrected line 9, $num = ""; and add
use CGI::Carp qw(fatalsToBrowser);

but this not help, same 'internal server error'. So I will wait responce from hosting support for logfile.
Re^3: where need be corrected to make script work?
created: 2006-04-05 09:14:53

It is quite easy to install ActiveState perl on Windows machines, and it would greatly improve your ability to test and learn perl.


___________
Eric Hodges
Re^3: where need be corrected to make script work?
created: 2006-04-05 09:25:50

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.


No good deed goes unpunished. -- (attributed to) Oscar Wilde
Re^3: where need be corrected to make script work?
created: 2006-04-05 10:21:25
I agree with the previous comments. INSTALL PERL ON YOUR PC (Sorry to yell but it sounds like that's the only way to get through to you)!

Just glancing at your script, you should check the path to sendmail. I don't think that is the standard path.

Re^3: where need be corrected to make script work?
created: 2006-04-05 13:56:29
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?!?

Re: where need be corrected to make script work?
created: 2006-04-05 09:34:33
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:

  1. 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 script.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).

  2. Asking your hosting provider what perl modules they have available for you to use. One good one is node 66313; a quick search on search.cpan.org also turns up others.

-- Burvil

Re^2: where need be corrected to make script work?
created: 2006-04-05 11:15:26
Is this non installing Perl on a machine a crime?

If someone can no do this, there are strong reasons to do so. 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
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..
Re^3: where need be corrected to make script work?
created: 2006-04-05 11:32:09
linex,

First of all, calm down. I do not believe that anyone here is being aggressive towards you. If you have not already done so, please read the PerlMonks FAQ

Secondly:

"I can no install anything that not related to my job. "

It seems to me that Perl is related to your job. Unless I have missed something your task (I assume a work related one) is to have a piece or Perl that performs a task. I do not believe that it is unreasonable to expect your employers to allow you to install the tools to do the job. Check out ActiveState.com, ActivePerl is free, so there is no need to worry about paying for it.

Hope this helps.

Martin
Re^3: where need be corrected to make script work?
created: 2006-04-05 11:33:46
Is this non installing Perl on a machine a crime?
No, it isn't, at least in most countries I know of - to me, it's an essential part of doing your job.

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

Re^3: where need be corrected to make script work?
created: 2006-04-05 11:35:41
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 help
Nobody 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?


holli, /regexed monk/
Re^3: where need be corrected to make script work?
created: 2006-04-05 11:36:30
Assuming this is Windows: You don't need to install Perl on your machine. Perl works perfectly fine if you try to run it directly from a CD-ROM. You will then have to use command lines like
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...

Re^4: where need be corrected to make script work?
created: 2006-04-05 11:48:51
well, I uploaded and run script on normal hosting. Not work, here is errors log:
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.cgi

So, dont know what is wrong in code if can no run even on normal hosting.
Re^5: where need be corrected to make script work?
created: 2006-04-05 11:54:17
It looks to me like all your errors listed here, are produced by not having the permission to open the log file. You'd have to set the file's permissions to writable for all. If you can't touch it where it is supposed to be, use a location of your own choice, for example in your home directory or in a dedicated subdirectory, and set the permissions accordingly. If the directory doesn't allow you to create a file, and it's unwise to allow it, make an empty file by hand with the proper name, set its permissions, and try again.
Re^6: where need be corrected to make script work?
created: 2006-04-05 14:51:44
I can no even get any errors in browser:
use CGI::Carp qw(fatalsToBrowser);

Script iself uses report.txt file for it work. I create this empty report.txt file and put it into cgi-bin directory, and set chmod 666.
Re: where need be corrected to make script work?
created: 2006-04-05 15:42:26
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.

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

Re: where need be corrected to make script work?
created: 2006-04-06 07:21:18

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,

planetscape
Re: I'm getting a 500 Internal Server Error - how can I make this work?
created: 2006-04-07 02:15:13
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 you have somehow manually created a file called "report.txt" and made sure it had global write access, then your script should not do this:
    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).

  • I don't understand why you are sending the same message, with all the same information to the same recipient, twice.

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 = ;
    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