Hi all, well I have the problem solved. The script uptime.pl
is appended below in it entirety. The problem lies with
the @db array (populated by 'more-ing' it). From this
array I want $db$i+16 and $db$i+17. From the command
line, the program works and I get what I want. But when
uptime.pl is accessed from a CGI script, $db$i+16 and
$db$i+17 are returning different data and so the script
sets @dataset values to '0'. If I change the @db
indicies to $db$i+18 and $db$i+19, then I get what
I want. Looks like through CGI, I get some extra lines
added to the more'd file. Anyway, to avoid this,
I have incorporated uptime.pl into the main CGI script
(don't know why I didn't do that in the first place!).
Thank you all for your help. Regards, Stacy.
#!/usr/local/bin/perl
use Date::Calc qw(Delta_DHMS);
@receivers = qw(70CM
50CM
H-OH
MULTIBEAM
GALILEO
MULTIBAND
METHANOL
K-BAND);
$dbfile = 'rxdb.dat';
#Get last modify time of DB file rxdb.dat
$mtime = (stat("$dbfile"))[9];
($fsec,$fmin,$fhour,$fmday,$fmonth,$fyear) =
localtime($mtime);
#Get current time
($nsec,$nmin,$nhour,$nmday,$nmonth,$nyear) =
(localtime(time))[0..5];
#Get current time
($nsec,$nmin,$nhour,$nmday,$nmonth,$nyear)
= (localtime(time))[0..5];
#Open DB and see if receivers are present and available
foreach $package (@receivers) {
open(DB, "$dbfile") or die "Can't open $dbfile!: $!";
$i = 0;
while ($line = <DB>) {
if ($line =~ m/package(\s+)= $package/i) { last }
$i++;
}
close(DB);
#$i lists the 'package =' line of the receiver we
#want. To determine if it is present and available,
#we require 'yes' to be found on lines $i+18 and
#$i+19
@db = `more $dbfile`;
if ($db[$i+18] =~ m/yes/ && $db[$i+19] =~ m/yes/) {
#Selected receiver is present & available.
#Calculate difference between file date and current date.
($days, $hours) =
Delta_DHMS(
$fyear+1900, $fmonth+1, $fmday, $fhour, $fmin, $fsec,
$nyear+1900, $nmonth+1, $nmday, $nhour, $nmin, $nsec);
$total = sprintf "%3.0f", ($days*24)+$hours;
} else {
$total = 0;
}
print "$package $total\n";
}
| [reply] [d/l] |