How to Run sqlplus as a cron Job & Fix “sqlplus: error while loading shared libraries: libsqlplus.so: cannot open shared object file: No such file or directory” Error?


If you have tried running Oracle sqlplus (of course through a script) in a cron job, then you might have encountered this error: –

sqlplus: error while loading shared libraries: libsqlplus.so: cannot open shared object file: No such file or directory

What happens is that, despite defining all the environment variables in /etc/profile or bash_profile, cron doesn’t recognise that & throws above error. Close inspection after debugging the script took me to a conclusion that sqlplus is not able to connect to database, because its not finding its shared library.

If you have encountered this issue, here is how to fix it? 😉

Make sure you have exported required variables. Below are my variables in my .bash_profile. Change yours accordingly.

export ORACLE_HOME=/u01/oracle/product/11.2.0/client_1/
export PATH=$ORACLE_HOME/bin:$PATH
export LD_LIBRARY_PATH=/u01/oracle/product/11.2.0/client_1/lib:usr/local/lib

Make sure you source your .bash_profile before executing the script in cron. Edit your script & add below line at the top.

source /home/shashank/.bash_profile

Now try executing the script in cron. It will be successful 😉 cron will first source the bash_profile, initialise all the variables & then execute the script 🙂

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s