lars_4 has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I am new here and i have a problem with my perl script. The scripts gets 3 columns of data from an oracle database, and passed 2 columns throught to a mysql sub. This sub then puts the data into an Mysql database. When this script is run direclty on the promt everything works fine. When run as a cron the seconds column gets corrupted somehow. All the numbers are xxx instead of the original numbers, sometimes the columns are just skipped. This is the code i made (not the best in the world i know):
#!/usr/bin/perl $ENV{'ORACLE_HOME'} = '/prog/oracle/10.2.0'; use DBI; use Mysql; use strict; #############MYSQL############### sub sub_mysql { my $myhost = "localhost"; my $mydatabase = "db"; my $mytablename = "table"; my $myuser = "user"; my $mypwd = "password"; my $myconn = Mysql->connect($myhost, $mydatabase, $myuser, $mypwd); $myconn->selectdb($mydatabase); my $myquery = "INSERT INTO $mytablename (date, status, well) VALUES (N +OW(),'$_[0]','$_[1]')"; my $myexecute = $myconn->query($myquery); } ###############END MYSQL################ ##############ORACLE SQL############## my $orahost = "oracle.bla.com"; my $oraport = "1000"; my $orasid = "I01"; my $orauser = ""; my $orapwd = ""; my $oraconn = "dbi:Oracle:HOST=$orahost;SID=$orasid;port=$oraport"; my $db = DBI->connect( $oraconn, $orauser, $orapwd ) || die( $DBI::err +str . "\n" ); my $oraquery = "SELECT date, status, well FROM bla where > sysdate -1 "; my $sth = $db->prepare($oraquery); $sth->execute(); my ($date, $well, $status); $sth->bind_columns(\$date, \$well, \$status); while( $sth->fetch() ) { sub_mysql("$status","$well"); } $db->disconnect; #############END ORACLE SQL#############
*please ignore the bad oracle sql statement* Hopefully someone knows what is going on..?

Replies are listed 'Best First'.
Re: Perl script not running correct as a cron
by JavaFan (Canon) on Jun 05, 2009 at 09:30 UTC
    It's most likely some kind of environment variable that isn't available when running the cron job. Processes running from cron don't run from a shell, so no profile has been set up. Considering that you don't have a username or password set for your Oracle connection, I'd make a guess some kind of authentication related environment setting is present when run from the shell, but not when run from cron.
      Thanks for the reply. I was also thinking about a environment variable. The Oracle server does not require username/pass and is open. If the username/pass was not working i should not get data at all, but i do get some. Only weird values... (in the status column.. the Well is 100% ok)
        Have you determined where it goes wrong? Is Oracle returning "weird" values? Or is MySQL inserting "weird" values? What happens if you trace the DBI?
Re: Perl script not running correct as a cron
by codeacrobat (Chaplain) on Jun 05, 2009 at 18:57 UTC