Re: I have a weird issue with a script running under cron

Bruce Johnson <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.general
Message-ID <[email protected]>
Well, I’ve identified my solution, but I’m not entirely certain why it’s working.

Setting the environment variables in a shell script wrapper around my perl script works. Despite %ENV being identical, when set within the perl script, I get the error, when set in the .sh wrapper it works.

It appears to be that called modules via ‘use MODULE;’ do NOT share the environment of the calling perl script?

These are my test scripts:

test.sh script

#!/bin/sh

ORACLE_HOME=/usr/lib/oracle/11.2/client64
LD_LIBRARY_PATH=$ORACLE_HOME/lib
ORACLE_SID=PHMWEB
export ORACLE_HOME LD_LIBRARY_PATH ORACLE_SID	
echo "testing connection" 
/home/allwebfiles/perl/kfs/test.pl 
echo "Done testing connection" 


test.pl script

#!/usr/bin/perl -w

$ENV{"ORACLE_HOME"}="/usr/lib/oracle/11.2/client64";
$ENV{"ORACLE_SID"}="phmweb";
$ENV{"LD_LIBRARY_PATH"}="/usr/lib/oracle/11.2/client64/lib";

use DBI;

my $login = 'scott';
my $dbpass = 'tiger';
my $dbhost='pharmacopeia.pharmacy.arizona.edu;sid=phmweb’<< substitute your own host here

print "Environment:\n";
foreach my $e (keys %ENV){
	print "env var $e = $ENV{$e} \n";
	}

print "\n";
print"DB test: sysdate = ";
my $dbh = DBI->connect( "dbi:Oracle:host=$dbhost", $login, $dbpass,
                      { RaiseError => 1 } );
my $csr= $dbh->prepare("select sysdate from dual");                      
$csr->execute();
my ($out) = $csr->fetchrow();
print "$out\n";
$csr->finish();
$dbh->disconnect;


I tested this first by commenting out the $ENV{}=‘’; lines in the perl script, leaving the ones in test.sh intact:

[root@merthiolate ~]# env -i /home/allwebfiles/perl/kfs/test.sh
testing connection
Environment:
env var ORACLE_HOME = /usr/lib/oracle/11.2/client64 
env var SHLVL = 1 
env var LD_LIBRARY_PATH = /usr/lib/oracle/11.2/client64/lib 
env var PWD = /root 
env var _ = /home/allwebfiles/perl/kfs/test.pl 
env var ORACLE_SID = PHMWEB 

DB test: sysdate = 19-FEB-14
Done testing connection

Then I commented out the first four lines of test.sh and uncommented the lines in test.pl

env -i /home/allwebfiles/perl/kfs/lddtest.sh
testing connection
Environment:
env var ORACLE_HOME = /usr/lib/oracle/11.2/client64 
env var LD_LIBRARY_PATH = /usr/lib/oracle/11.2/client64/lib 
env var SHLVL = 1 
env var PWD = /root 
env var _ = /home/allwebfiles/perl/kfs/test.pl 
env var ORACLE_SID = phmweb 

install_driver(Oracle) failed: Can't load '/usr/local/lib64/perl5/auto/DBD/Oracle/Oracle.so' for module DBD::Oracle: libocci.so.11.1: cannot open shared object file: No such file or directory at /usr/lib64/perl5/DynaLoader.pm line 200.
 at (eval 3) line 3
Compilation failed in require at (eval 3) line 3.
Perhaps a required shared library or dll isn't installed where expected
 at /home/allwebfiles/perl/kfs/test.pl line 18
DB test: sysdate = Done testing connection

It appears that DBI is NOT inheriting the environment when it’s called via ‘use DBI’ even though it’s called after I explicitly set them within the perl script.


-- 
Bruce Johnson
University of Arizona
College of Pharmacy
Information Technology Group

Institutions do not have opinions, merely customs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.