Richard Luckhurst wrote:
Hi All
I am a perl newbie.
I have a small perl script that is actually a cgi-bin script. I am told that
until a recent server change over it ran fine however now it produces no output.
I have tried running it from a command line and redirecting the input it would
have received as a cgi-bin script from a text file. I am getting a couple of
"Use of uninitialized value in concatenation (.) or string" errors and I can not
see why.
The script is as follows
#!/usr/bin/perl
#
# log-errors cgi-bin script to display the last 2000 lines of an error log.
# domain is the domain name of the virtual apache server
#
require '/www/server/cgi-bin/cgi-lib.pl';
&ReadParse(*in);
$domain = $in{'domain'};
print "Content-type: text/html\n\n";
print "<html><head><title>Exodus Web Server Log</title></head>\n";
print "<body link=\"blue\" vlink=\"blue\">\n";
print "<font size=\"4\"><b>Last 2000 Lines of the Error log for:
$domain</b></font><br>\n";
print "<font size=\"1\"><br></font>Go to <a href=\"#bottom\"><i>End of
log</i></a><br><br>\n";
$tail = `tail -n2000 /var/log/httpd/$domain-error_log 2>/dev/null |
tac`;
$tail =~ s/</<\;/g;
$tail =~ s/>/>\;/g;
print "<pre>$tail<\/pre>\n";
print "<a name=\"bottom\"></a>";
print "<br><b>End of log</b><br>\n";
print "</body></html>\n";
exit 0;
When I run the script from the command line with the command
perl -w log-err* < test.txt
Where test.txt contains domain=www.resmaster.com
I get the following output
Content-type: text/html
<html><head><title>Exodus Web Server Log</title></head>
<body link="blue" vlink="blue">
Use of uninitialized value in concatenation (.) or string at log-errors line 10.
<font size="4"><b>Last 2000 Lines of the Error log for: </b></font><br>
<font size="1"><br></font>Go to <a href="#bottom"><i>End of log</i></a><br><br>
Use of uninitialized value in concatenation (.) or string at log-errors line 12.
<pre></pre>
<a name="bottom"></a><br><b>End of log</b><br>
</body></html>
It seems that the value of the domain is not being passed in correctly and it is
not being passed down through the script.
When I run the script as a cgi-bin script called from a web page I get the html
code produced by the print statements but I get nothing from the $tail variable.
This is what I would expect as I get nothing between the <pre></pre> tags when I
run it from a command line.
I would appreciate any help in sorting out this problem.
Hello Richard
You are right that your problem is almost certainly because $domain is not being
set up properly, but the error lies in the ReadParse() subroutine in the
cgi-lib.pl file which you don't show. You are looking at a very old piece of
Perl programming which is doing things in ugly ways, so please don't try to
learn anything from its methods!
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>