SantaClaus has asked for the wisdom of the Perl Monks concerning the following question:
I have a script that uses DBI and DBD::Oracle. My sysadmin had some trouble getting DBD::Oracle to work, and in the end used a LD_LIBRARY_PATH=$ORACLE_HOME hack over which I have no control. The trouble is that DBD::Oracle is now compiled with this, and I can not run my script without setting that env var.
I plan to run the script in cron, and I know I can just do "env LD_LIBRARY_PATH=<path_to_oracle> my_script.pl." It works, I've tested it. We have other scripts that run that way now. But that just seems ugly to me. The script already has many configuration options set in a conf file, and it seems more elegant and consistent to set LD_LIBRARY_PATH in there. My shop also has standard modules for Oracle connections and config files that I'd like to use.
I've tried:
my $config; # scoped to script so I can continue to use it BEGIN { require Our::Config::Module; import Our::Config::Module; $config = new Our::Config::Module('filename') or die "Can't read config file\n"; $ENV{LD_LIBRARY_PATH} = $config->get('lib_path'); } use Our::Oracle::Module;
But this dies at compile time with the usual
"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. at /usr/lib/perl5/site_perl/5.8.5/Our/Oracle/Module.pm line 27 Compilation failed in require at /usr/lib/perl5/site_perl/5.8.5/Our/Oracle/Module.pm line 27."
that I always see when LD_LIBRARY_PATH is not set. So I'm assuming that's not an acceptable way to set env vars before use-ing modules that rely on them.
I strongly prefer to maintain portability by keeping machine specific stuff in a config file that I can modify without making code changes. Remember too that I have actual sysadmins, so I have no control over the Perl installation and don't want to maintain a separate one. With these restrictions, can anyone propose a clean way to set the env var that does not involve hard coding the path, either in the script or in the cron job? Or am I just letting an unaccountable fastidiousness lure me away from a perfectly good solution that I know works?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: set env var at compile time
by moritz (Cardinal) on Jun 26, 2008 at 21:23 UTC | |
|
Re: set env var at compile time
by songmaster (Beadle) on Jun 26, 2008 at 21:32 UTC | |
|
Re: set env var at compile time
by diotalevi (Canon) on Jun 26, 2008 at 20:55 UTC | |
by SantaClaus (Initiate) on Jun 26, 2008 at 21:16 UTC | |
|
Re: set env var at compile time
by kyle (Abbot) on Jun 26, 2008 at 20:59 UTC | |
by SantaClaus (Initiate) on Jun 26, 2008 at 21:25 UTC | |
by kyle (Abbot) on Jun 26, 2008 at 21:28 UTC |