thank you Mr Boyle for the help. i have been able to
gain access to the directory, but i still cannot get
any HTML output from the script. the browser just
hangs when i try to access it. i figure the problem
might have to do with the code, and i was wondering if
anyone could help me debug. the script takes an INFILE
which i have created in the same directory and after
processing the file it goes into a sleep mode for 1
minute. somehow no HTML output is piped out. here is
what the script looks like:
should i remove the infinite loop construct to stop
the hang? please help
=======================================================
#!/usr/bin/perl
#test4.pl
# Number of Sample points to make running average of
is supplied as a command line argumnt
$num_samples= 15;
# Set minimum and maximum to arbitrarily high and low
values respectively
$min_temp = 100.0;
$max_temp = -100.0;
@minimum=split(/ +/,localtime());
$min_temp_time=$minimum[3];
$min_temp_date=$minimum[1]." ".$minimum[2];
@maximum=split(/ +/,localtime());
$max_temp_time=$maximum[3];
$max_temp_date=$maximum[1]." ".$maximum[2];
# Infinite Loop to run as a daemon
for(;;)
{
# Open temperature.dat for input (contains
$num_samples lines of the format
# temperature Tue 28 00:00:00 2001
open(INFILE,"<temperature.dat") || die "Can't open
inputfile";
# Read all the data into a single array
# Each element of array contains one line of file
@inputs=<INFILE>;
close(INFILE);
# $num_lines contains number of lines in the file
$num_lines=@inputs;
# Check to see if the number of lines is greater than
number of sample points to average over
if ($num_lines >= $num_samples)
{
# If true then average over the temperature field and
also find the minimum and maximum values for
temperature.
# Initialize counter,sum and average
$counter = 1;
$sum = 0.0;
$average = 0.0;
while($counter <= $num_samples)
{
# Split each element of input array on whitespace
@data = split(/ +/,$inputs[$num_lines-$counter]);
# Extract the first field as temperature
$temperature = $data[0];
$data_time = $data[4];
$data_date= $data[2]." ".$data[3];
if ($data_date ne $min_temp_date)
{
$min_temp_date=$data_date;
$min_temp=$temperature;
$min_temp_time=$data[4];
$max_temp_date=$data_date;
$max_temp=$temperature;
$max_temp_time=$data[4];
}
# Find the minimum and maximum temperature of
num_sample points
if ($temperature < $min_temp)
{ $min_temp = $temperature;
$min_temp_time=$data_time;
$min_temp_date=$data_date;
}
if ($temperature > $max_temp)
{ $max_temp = $temperature;
$max_temp_time=$data_time;
$max_temp_date=$data_date;
}
$sum += $temperature;
$counter++;
}
# Compute average
$average = $sum/($counter-1);
$current_time=localtime;
print <<"Tempstuff";
Content-type: text/html
<HTML>
<TITLE>Weather</TITLE>
<BODY BGCOLOR="#000000" TEXT="#FFFFFFF">
<P><EM><H1 ALIGN=CENTRE>TEMPERATURE
DATA</H1></EM></P>
<HR WIDTH=80% ALIGN=CENTRE>
<P><FONT TEXT="FF0033">Average Temperature for
the past $num_samples
minutes: $average</FONT></P>
</BODY>
</HTML>
Tempstuff
}
else
{
sleep(1*60);
}
# End of If $numlines < $numsamples condition
sleep(1*60);
}
=======================================================
--- Owen Boyle <[EMAIL PROTECTED]> wrote:
> Keletso Mokgethi wrote:
> > i am a novice trying to run a perl script on
> apache
>
> > i created
> > a directory under httpd called "perl" in which i
> > stored the script. according to redhat's linux 6.2
> > apache/ssl documentation, mod_perl is ready to run
> > once the server is launced and there is no need
> for
> > any changes in httpd.conf
>
> Hold it right there! If you created a directory, you
> had better tell
> apache about it - for that you *need* to edit
> httpd.conf... let's
> proceed.
>
> > hoping to run the script i entered the URL:
> > http://localhost/perl/Read_dat.perl/
> >
> > and got the reponse: Forbidden
> >
> > "you don't have permission to access
> > /perl/Read_dat.perl/ on this server.
>
> There are a few reasons why you might get this... In
> short, apache has
> to be able to find the program and access to the
> directory has to be
> "allowed".
>
> Before doing anything else, look in httpd.conf until
> you find the
> ErrorLog directive, then find the file it is
> pointing to and tail that
> file while you run your prog to see what errors you
> are getting ($ tail
> -f /home/apache/logs/error_log)
>
> Back to the problem: I think you are trying to run
> your script using the
> Apache::Registry. To do this:
>
> - let's assume your ServerRoot is "/home/apache"
> - check mod-perl is compiled into apache ($
> /home/apache/bin/httpd -l
> and look for mod_perl)
> - put your script in /home/apache/perl (already
> done)
> - check it is executable ($ chmod +x Read_dat.perl)
> - its first output has to be the script-header
> (print "Content-type:
> text/html\n\n"; - NB note the two "\n").
> - in httpd.conf, you need the following
>
> <Directory /home/apache/perl> # this "allows"
> apache into the directory
> Allow from all
> </Directory>
>
> Alias /perl/ /home/apache/perl/ # this lets it find
> the script
> <Location /perl> # this tells it
> what to do
> SetHandler perl-script
> PerlHandler Apache::Registry
> Options +ExecCGI
> </Location>
> - restart apache
> - hit the URL; http://localhost/perl/Read_dat.perl
>
> By the way, in case you don't actually have
> mod_perl, bear in mind that
> you don't need to use mod_perl to get apache to
> execute a perl program.
> You can just use plain old-fashioned CGI. A simple
> configuration that
> might get you running quicker is:
>
> - create a directory /home/apache/cgi and put
> Read_dat.perl into it
> - make sure it is executable
> - its first output has to be the script-header
> (print "Content-type:
> text/html\n\n"; - NB note the two "\n").
> - in httpd.conf:
>
> <Directory /home/apache/cgi>
> Allow from all
> </Directory>
> DocumentRoot /home/apache/html
> ScriptAlias /cgi /home/apache/cgi
>
> - restart apache
> - hit the URL; http://localhost/cgi/Read_dat.perl
>
> Now you should get some output.
>
> Check the error_log to see if anything goes wrong
> (this will log
> apache-level errors). If you need to debug your
> program, switch on
> script-logging:
>
> ScriptLog logs/script_log
>
> and this will log STDERR from the script.
>
> best regards,
>
> Owen Boyle.
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/