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

Hi everyone.

I want to create a crawler with perl and run it on crowntab. The program should use DBI and DBD::Oracle to insert data into my database.

When crontab runs it, I get the following error in my mail box.

Can't load '/usr/lib/perl5/site_perl/5.8.5/i386-linux-thread-multi/auto/DBD/Oracle/Oracle.so' for module DBD::Oracle: libclntsh.so.10.1: cannot open shared object file: No such file or directory at /usr/lib/perl5/5.8.5/i386-linux-thread-multi/Dynaloader.pm line 230.

my code is something like:

#!/usr/bin/perl

use Getopt::Long;
use POSIX;
use POSIX qw(setsid);
use warnings;
use Data::Dumper;
use WWW::Mechanize;
use DBI;
use DBD::Oracle;
use XML::Twig;

init_env();

#do something-----

sub init_env
{
$SIG{'INT'} = 'IGNORE';
$SIG{'QUIT'} = 'IGNORE';
$SIG{'TERM'} = 'IGNORE';
$SIG{'PIPE'} = 'IGNORE';
# signal(SIGPIPE, SIG_IGN);
$SIG{'CHLD'} = 'IGNORE';

my $pid = fork(); die "$!" unless defined $pid; exit 4 if $pid;

POSIX::setsid() or die "Can't start a new session: $!";

# Flush standard output buffer.
select(STDOUT);
$| = 1;
}

BEGIN
{
$ENV{ORACLE_HOME} = "/u01/oracle/product/10.2.0/client_1";
$ENV{PATH} = "/bin:/usr/bin:/u01/oracle/product/10.2.0/client_1/bin:/home/appowner/bin:.";
$ENV{LD_LIBRARY_PATH} = "/u01/oracle/product/10.2.0/client_1/lib";
}
END {

}

I have installed both DBI and DBD::Oracle with CPAN.

Please help and many thanks.

Shen

Replies are listed 'Best First'.
Re: DBD::Oracle error
by Anonyrnous Monk (Hermit) on Jan 26, 2011 at 22:40 UTC
    ... libclntsh.so.10.1: cannot open shared object file ...

    Try setting LD_LIBRARY_PATH before starting the script. Or re-exec the program — something like this (at the beginning of the script):

    BEGIN { my $prahome = "/u01/oracle/product/10.2.0/client_1"; my $oralib = "$orahome/lib"; unless ($ENV{LD_LIBRARY_PATH} =~ /\Q$oralib/) { # avoid endless l +oop $ENV{ORACLE_HOME} = $orahome; $ENV{LD_LIBRARY_PATH} = $oralib; $ENV{PATH} = "/bin:/usr/bin:$orahome/bin:/home/appowner/bin:." +; exec $0, @ARGV; } }

    Some OSes / dynamic loaders cache the lib search paths upon exec, so setting them after starting the process has no effect.

Re: DBD::Oracle error
by williamshen25 (Initiate) on Jan 27, 2011 at 00:44 UTC
    Hey I have figured out there is something wrong with my DBD installation, I corrected it and it run fine when I do it manually on command line, but still getting same error when crontab calls it. I read it on some other site that people suggest to set LD_LIBRARY_PATH to point to where the shared library is. But as you can see, I have set it to the location where "libclntsh.so.10.1" is located. =(

      williamshen25:

      Keep in mind that your login environment and the environment that crontab provides to the processes it spawns are different. I'd check that first if you're using the same user ID for your login and crontab. If you're running under a different user, you'll also have to check permissions and such.

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.