e.b.white
e.b.white

Reputation: 783

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

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?

Upvotes: 25

Views: 184826

Answers (12)

Alberto M
Alberto M

Reputation: 1760

I had to install the dependency

oracle-instantclient12.2-basic-12.2.0.1.0-1.x86_64

Upvotes: 1

Guru
Guru

Reputation: 2857

probably you need to sudo into an account registered with relevant env settings :)

Upvotes: 0

JSharm
JSharm

Reputation: 1197

For the benefit of anyone else coming here by far the best thing to do is to update cx_Oracle to the latest version (6+). This version does not need LD_LIBRARY_PATH set at all.

Upvotes: 0

Ritesh Maddala
Ritesh Maddala

Reputation: 1

I have copied all library files from installer media databases/stage/ext/lib to $ORACLE_HOME/lib and it resolved the issue.

Upvotes: 0

Cleber Spirlandeli
Cleber Spirlandeli

Reputation: 143

I always have this problem, I can solve by running the code below: export LD_LIBRARY_PATH=/opt/oracle/instantclient:$LD_LIBRARY_PATH

enter image description here

OBS: This code I saved in the configuration file because I always use it. good luck.

Upvotes: 0

ol3man
ol3man

Reputation: 31

If you have problem with libclntsh.so, need create symlink for libclntsh.so from /usr/lib/oracle/11.2/client64/lib to /usr/lib

Upvotes: 3

Ujjawal Khare
Ujjawal Khare

Reputation: 796

Just pass your Oracle path variables before you run any scripts:
Like for perl you can do add below in beginning of your script:

BEGIN {
   my $ORACLE_HOME     = "/usr/lib/oracle/11.2/client64";
   my $LD_LIBRARY_PATH = "$ORACLE_HOME/lib";
   if ($ENV{ORACLE_HOME} ne $ORACLE_HOME
   || $ENV{LD_LIBRARY_PATH} ne $LD_LIBRARY_PATH
   ) {
      $ENV{ORACLE_HOME}     = "/usr/lib/oracle/11.2/client64";
      $ENV{LD_LIBRARY_PATH} = "$ORACLE_HOME/lib";
      exec { $^X } $^X, $0, @ARGV;
   }
}

Upvotes: 0

Josemar Furegatti
Josemar Furegatti

Reputation: 31

This post helped me solve a similar problem with a PostgreSQL database link to Oracle using oracle_fdw.

I installed oracle_fdw but when I tried CREATE EXTENSION oracle_fdw; I got error could not load library libclntsh.so.11.1: cannot open shared object file: No such file or directory.

I checked $ORACLE_HOME, $PATH and $LD_LIBRARY_PATH.

It worked only AFTER I put Oracle Shared Library on Linux Shared Library

echo /opt/instantclient_11_2 > oracle.conf
ldconfig

Upvotes: 3

Dimitri
Dimitri

Reputation: 91

The libs are located in /u01/app/oracle/product/11.2.0/xe/lib (For Oracle XE) or similar.

You should add this path to /etc/ld.so.conf or if this file shows only an include location, as in a separate file in the /etc/ld.so.conf.d directory

I have oracle.conf in /etc/ld.so.conf.d, just one file with the path. Nothing else.

Of course don't forget to run ldconfig as a last step.

Upvotes: 9

Jay Taylor
Jay Taylor

Reputation: 13562

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.

Upvotes: 2

Yasir Arsanukayev
Yasir Arsanukayev

Reputation: 9676

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.

Upvotes: 18

mmmmmm
mmmmmm

Reputation: 32710

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

Upvotes: 3

Related Questions