M
Matt Cluver
Hello All,
I'm having a problem with crontab running my perl script, it runs
perfectly fine from the prompt while logged in. The script is chmodded
to 777, I have included a lib statement to take care of possible
enviroment variable issues.
I would appreciate someone taking a look, thanks in advance.
Cheers!
Matt
Crontab:
0 0 * * * perl /full/path/to/qotd.pl
Perl:
#!/usr/bin/perl
use lib '/full/path/to/cgi-bin';
require ".sys.conf";
use rcgi;
use Mysql;
my $cgi = new rcgi;
my %d = $cgi->get_data();
my $dbh = Mysql->connect($db_host, $db_name, $db_user, $db_pass);
if ($d{'cmd'} eq "prcsAdd") {
$cgi->print_header();
&page_header();
&process_add();
&page_footer();
exit();
}
else { &printRandomQuote(); }
sub printRandomQuote()
{
$q = "select qid from qotd";
$sth = $dbh->Query($q) || &error_exit("<b>Error running query</b>:
$q");
$num = $sth->NumRows();
$i=0;
while (my @res = $sth->FetchRow())
{
$res2[$i] = $res[0];
$i++;
}
$i=0;
$index = rand @res2;
$rand_id = $res2[$index];
$query = "select qotd from qotd where qid='$rand_id'";
$sth = $dbh->Query($query) || &error_exit("<b>Error running query</b>:
$query");
my @quote = $sth->FetchRow();
open (QUOTE, ">/full/path/to/quote.html");
print QUOTE "$quote[0]";
close (QUOTE);
}
I'm having a problem with crontab running my perl script, it runs
perfectly fine from the prompt while logged in. The script is chmodded
to 777, I have included a lib statement to take care of possible
enviroment variable issues.
I would appreciate someone taking a look, thanks in advance.
Cheers!
Matt
Crontab:
0 0 * * * perl /full/path/to/qotd.pl
Perl:
#!/usr/bin/perl
use lib '/full/path/to/cgi-bin';
require ".sys.conf";
use rcgi;
use Mysql;
my $cgi = new rcgi;
my %d = $cgi->get_data();
my $dbh = Mysql->connect($db_host, $db_name, $db_user, $db_pass);
if ($d{'cmd'} eq "prcsAdd") {
$cgi->print_header();
&page_header();
&process_add();
&page_footer();
exit();
}
else { &printRandomQuote(); }
sub printRandomQuote()
{
$q = "select qid from qotd";
$sth = $dbh->Query($q) || &error_exit("<b>Error running query</b>:
$q");
$num = $sth->NumRows();
$i=0;
while (my @res = $sth->FetchRow())
{
$res2[$i] = $res[0];
$i++;
}
$i=0;
$index = rand @res2;
$rand_id = $res2[$index];
$query = "select qotd from qotd where qid='$rand_id'";
$sth = $dbh->Query($query) || &error_exit("<b>Error running query</b>:
$query");
my @quote = $sth->FetchRow();
open (QUOTE, ">/full/path/to/quote.html");
print QUOTE "$quote[0]";
close (QUOTE);
}