Wits end with Python and cron

Fredrik Lundh fredrik at pythonware.com
Wed Sep 28 15:08:25 EDT 2005


Justin Delvecchio wrote:

> I've researched this problem for the last few days.  Say I have
> the following script that I execute from cron on linux.  Yes, the
> following runs quite fine from the command line:

> And the error I continually get is:
>
> Traceback (most recent call last):
>   File "/home/oracle/rods_dbf_file/map_unix.py", line 29, in ?
>     import cx_Oracle
> ImportError: libclntsh.so.10.1: cannot open shared object file:
> No such file or directory

> What is going on?  I've googled this thing to death and it seems like I've
> got two different solutions, PYTHONPATH and LD_LIBRARY_PATH,
> that should satisfy this.  /u01/app/oracle/product/10.1.0/Db_1/lib is where
> the lib resides.

have you read the cron documentation?  if you had done that, you would
perhaps have noticed that cron runs jobs with a rather minimal environment.

if you don't make sure to add the variables required by your program (in
this case, LD_LIBRARY_PATH), the cron job will fail. (this is true for any
program run under cron, not just Python programs).

if you're running a python program directly from cron, you can simply add
to the environment inside the Python program, before you start importing
stuff:

    import os # make sure we can load the oracle libraries
    os.environ["LD_LIBRARY_PATH"] = "/u01/app/oracle/..."

    import cx_Oracle

other approaches include adding a small shell script that sets things up
properly before running the Python script (and running that shell script
from cron), and adding environment settings to the crontab file (see the
cron/crontab documentation for details).

</F> 






More information about the Python-list mailing list