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.
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 🙂