Welcome to WebmasterWorld Guest from 54.167.177.207

Forum Moderators: coopster & jatar k & phranque

Use of uninitialized value in string at ebaylogs.cgi line 8

Death of perl? Not on your life!

   
4:25 am on May 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Death of perl? Not as long a I'm still a perl n00bie, as I've been for 13 years!


I upgraded my server, and a simple log script doesn't work. If I have the code...

#!/usr/bin/perl
use CGI;
use strict;
use warnings;

my $database = "/full_path/file.shtml";

my $REMOTE_ADDR = "$ENV{'REMOTE_ADDR'}";
my $SCRIPT_URI = "$ENV{'SCRIPT_URI'}";
my $HTTP_USER_AGENT = "$ENV{'HTTP_USER_AGENT'}";
my $HTTP_REFERER = "$ENV{'HTTP_REFERER'}";

my $shortdate = `date +"%D %T %Z"`;
chop ($shortdate);
open (DATABASE,">>$database");
print DATABASE "$REMOTE_ADDR - $shortdate - $SCRIPT_URI - $HTTP_USER_AGENT<!-- - $HTTP_REFERER--><BR>\n";
close(DATABASE);

{
print "Content-Type: text/html\n\n";
print <<EOM;
<PRE>
</PRE>
EOM
exit;
}

Only the date get's added to the database and through SSH, it spits out...


Use of uninitialized value in string at file.cgi line 8.
Use of uninitialized value in string at file.cgi line 9.
Use of uninitialized value in string at file.cgi line 10.
Use of uninitialized value in string at file.cgi line 11.
7:06 am on May 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If it would be easier to get this version working, the much simpler working version before upgrading was...


#!/usr/bin/perl
use CGI ':standard';

$database = "/full_path/filename.shtml";

$shortdate = `date +"%D %T %Z"`;
chop ($shortdate);
open (DATABASE,">>$database");
print DATABASE "$ENV{'REMOTE_ADDR'} - $shortdate - $ENV{'SCRIPT_URI'} - $ENV{'HTTP_USER_AGENT'}<!-- - $ENV{'HTTP_REFERER'}--><BR>\n";
close(DATABASE);
{
print "Content-Type: text/html\n\n";
print <<EOM;
<PRE>
</PRE>
EOM
exit;
}
9:29 am on May 25, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



the environment variables for REMOTE_ADDR etc are set by the webserver, so they don't exist if you run the script via ssh and are undefined.
Does it work when run as a CGI?
12:27 pm on May 25, 2010 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



those aren't errors, they are warnings and you are using the warning pragma.

you could probably get rid of the warning with something like:
my $REMOTE_ADDR = $ENV{'REMOTE_ADDR'} || "";

although it should probably run as is without warning as a CGI script.
4:26 pm on May 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Through the browser it spits out the useless ISE message, which is the only reason I was on SSI, to get useful errors.

#!/usr/bin/perl

use strict;
use warnings;
use POSIX qw(strftime);
use CGI;
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);

my $cgi = CGI->new;
my $database = "/full_path/file.shtml";
my $shortdate = strftime("%m/%d/%y %H:%M:%S %Z", localtime);
my $remote_addr = $ENV{'REMOTE_ADDR'} || 'N/A';
my $script_uri = $ENV{'SCRIPT_URI'} || 'N/A';
my $http_user_agent = $ENV{'HTTP_USER_AGENT'} || 'N/A';
my $http_referer = $ENV{'HTTP_REFERER'} || 'N/A';

print $cgi->header, $cgi->start_html;
warningsToBrowser(1);
print $cgi->p("$remote_addr - $shortdate - $script_uri - $http_user_agent<!-- - $http_referer-->");

open my $dbhandle, '>>', $database
or die "failed to open '$database' for appending: $!";

print $dbhandle "$remote_addr - $shortdate - $script_uri - $http_user_agent<!-- - $http_referer--><BR>\n";
close $dbhandle;

generates no errors on SSH, but just spits out

N/A - 05/25/10 09:15:02 PDT - N/A - N/A

On the site the script is called via SSI and doesn't spit out anything.
4:33 pm on May 25, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



when running it through ssh, do you invoke it with
./ebaylogs.cgi
or with
perl ebaylogs.cgi?

could be that line-endings are wrong, chmod isn't set correctly or the shebang is not correct.
However, it's weird that calling it via SSI (which did you use, include file or include virtual?) doesn't even produce an error.

since you do have access via ssh, did you take a look at the webserver's errorlog? it should tell you why it throws an 500 Internal Server Error.
5:57 pm on May 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I've been using

perl ebaylogs.cgi



./ebaylogs.cgi

just spits out...

[root@me cgi-bin]# ./ebaylogs.cgi
-bash: ./ebaylogs.cgi: /usr/bin/perl^M: bad interpreter: No such file or directory

while perl ebaylogs.cgi
now shows

[root@me cgi-bin]# perl ebaylogs.cgi
Content-Type: text/html; charset=ISO-8859-1

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<p>N/A - 05/25/10 10:53:14 PDT - N/A - N/A<!-- - N/A--></p>



It's chmoded 755, and I just changed the cgi-bin directory to 755 and it does the same thing.


/var/log/httpd/error_log

shows no hint of ISE messages. Only errors generated today are

[Tue May 25 01:53:22 2010] [error] [client 213.239.220.45] File does not exist: /var/www/vhosts/default/htdocs/phpmyadmin
[Tue May 25 02:39:04 2010] [error] [client 61.139.105.162] File does not exist: /var/www/vhosts/default/htdocs/st

I got...

This is perl, v5.8.8 built for i386-linux-thread-multi
7:06 pm on May 25, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



-bash: ./ebaylogs.cgi: /usr/bin/perl^M: bad interpreter: No such file or directory

that pretty much says line endings.
the interpreter is not found. It might be /usr/bin/perl, but the line ending on unix/linux is \n, so anything before that will be seen as part of the interpreter an it's arguments.
three options: either fix the line endings (many editors have a "convert to unix"-function) or/and change between ascii and binary ftp mode, should you use ftp. the third, while not being the cleanest, is probably the easiest:
replace
#!/usr/bin/perl
with
#!/usr/bin/perl -w
that'll call /usr/bin/perl as the interpreter and pass -w as an additional argument to perl so it knows it should enable warnings. perl itself does not care about line endings, so that should work just fine.
8:12 pm on May 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I started getting a *useful* 'ISE' message...

97.125.24.27 - 05/25/10 11:18:46 PDT - N/A - Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.3) Gecko/20100401 Ant.com Toolbar 2.0.1 Firefox/3.6.3

Software error:

failed to open '/var/www/vhosts/ANOTHERDOMAIN.com/httpdocs/craigslist/file.shtml' for appending: Permission denied at thisfile.cgi line 21.

which is

open my $dbhandle, '>>', $database
or die "failed to open '$database' for appending: $!";

so I then moved the log file to the same domain, chmod it 777, changed the path in the script...and the original version of the script worked just fine.

Is there any way to make the script be allowed to post data to a file in another domain on the same server? The file on the other domain and the directory that it's in is both chmod 777.
2:40 am on May 26, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



chmod'ing all folders back to the domain 777 does it. For example, two folders and a file...

httpdocs/folder/file.shtml

and it then works.
9:44 am on May 26, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



I'm guessing you are using suexec, so that cgi-scripts are run as the user they belong to. Maybe you should put the datafiles of all domains somewhere outside the document root and make that world writeable, since giving full access to the other domain to everybody kind of defeats the purpose of suexec.
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month