views:

646

answers:

4

I want to schedule a task on linux by icrontab, and the task is written in python and have to import cx_Oracle module, so I export ORACLE_HOME and LD_LIBRARY_PATH in .bash_profile, but it raise the error:

libclntsh.so.11.1: cannot open shared object file. 

Since it is ok to run the task by issue the command in shell like

python a.py     #  ok

I change the task in icrontab into a shell script which invoke my python script, but the exception recurred?

# the shell script scheduled in icrontab
#! bash 
python a.py    

Could you help how to do with it?

+3  A: 

Possibly you want to specify PATH — and also ORACLE_HOME and LD_LIBRARY_PATH — so that cron(1) knows where to find binaries.
Read "5 Crontab environment" here.

Yasir Arsanukaev
but we I update the shell script as below: #! /bin/bashecho $ORACLE_HOMEecho $LD_LIBRARY_PATH and redirect the output of crontab to log filewhy these path have been found and writted to log?
e.b.white
@zhangzhong I suppose you'd like to use `export` not `echo` ? E. g. `export ORACLE_HOME=/usr/lib/oracle10/foo` and `export LD_LIBRARY_PATH=/usr/lib/bar`
Yasir Arsanukaev
+1  A: 

Cron does not load the user's profile when running a task and you have to include the profile in your shell script explicitly.

Example documentation

Mark
A: 

I ran into this same problem last weekend when I needed to use cx_Oracle. After spending a lot of time trying to modify the LD_LIBRARY_PATH variable to include the $ORACLE_HOME/lib directoy, where libclntsh.so resides, I ended up solving the problem by creating symbolic links from all the Oracle xlibx.so libraries into /lib/xlibx.so. This certainly isn't the "cleanest" solution, but it has a good chance of working without causing too much trouble:

 cd $ORACLE_HOME/lib
 for f in `ls ./*.so*`; do;
   sudo ln -s $ORACLE_HOME/lib/$f /lib/$f 
 done

After I did that, cx_Oracle worked like a charm.

pyrony
I have solved it after including in the script: . ~/.bash_profile
e.b.white
Where did you include the script from?
pyrony
Technically this will work, but it's the wrong answer, since the next time you update the Oracle client this can break (and would need to be re-run). The better answer is to fix the script that needs Python/Oracle and set the environment values correctly.
Craig Trader
A: 

have you already download the basic package ? because i stupidly forget to download the basic library is located there.

unknown