20090908 dbdoracle and cron - plembo/onemoretech GitHub Wiki

title: DBD::Oracle and cron link: https://onemoretech.wordpress.com/2009/09/08/dbdoracle-and-cron/ author: lembobro description: post_id: 256 created: 2009/09/08 18:41:58 created_gmt: 2009/09/08 18:41:58 comment_status: open post_name: dbdoracle-and-cron status: publish post_type: post

DBD::Oracle and cron

So, everyone knows that cron runs things with absolutely no user environment at all. Well, not exactly. On Linux, for example, It actually uses the “default” environment that probably includes “PATH=/usr/bin:/bin” and little else. As a result launching any kind of script using cron can be a problem.

I recently ran into this when trying to run my Oracle tablespace usage reporting script. On my box I didn’t have the Oracle client libraries used to compile DBD::Oracle included in the system /etc/ld.so.conf because I wanted to maintain the ability to run apps that used different versions of those libraries (e.g. from the full Oracle Client app so I could use its admin tools). As a result, I had the path to those libs defined as part of LD_LIBRARY_PATH in my .bash_profile.

But cron ignores your .bash_profile, so the LD_LIBRARY_PATH variable still needs to be defined for DBD::Oracle run under cron to find those libs.

No matter what I tried inside the script itself, nothing worked. This included using a BEGIN {} wrapped around a $ENV{'LD_LIBRARY_PATH'} = "/opt/oracle/instantclient_11_1" at the top of the script.

I finally got it to work by defining LD_LIBRARY_PATH in my crontab, like so:

0 3 *** LD_LIBRARY_PATH=/opt/oracle/client /usr/bin/perl /home/myuser/bin/oracletbl.pl

Not entirely happy with this solution, but it works.

Another way is to write a shell script wrapper in which the variable is declared and then the perl script launched.

Finally, for a truly sledge hammer approach, you can simply define the variable at the top of the crontab itself, so it will be set for all scripts that execute out of it. Of course, being a sledge hammer kind of guy, this is the one I’m now using.

If anyone has a better idea, let me know.

Copyright 2004-2019 Phil Lembo