Link to home
Start Free TrialLog in
Avatar of YZlat
YZlatFlag for United States of America

asked on

oraenv not found error

In my ksh script i set the environmental variables as follows:

#!/bin/ksh
ORAENV_ASK=NO
export ORACLE_SID=ORCL
. oraenv
export ORACLE_HOME

when I run the script manually, it runs fine, but when I run it via crontab, I get this error.

How can I avoid getting this error. Should I try using

. ${HOME}/.profile

or
. /home/oracle/.profile ${ORACLE_SID}

?
Avatar of David VanZandt
David VanZandt
Flag of United States of America image

Put your environment and explicit paths into the shell script.
Avatar of YZlat

ASKER

The thing is I want it to be dynamic, that's the whole reason I removed the explicit path that was hardcoded
When you run any script via crontab you need to set for it environment, and when you refer to files or directories then you refer by full path names. You could try the following before sourcing the oraenv file:

cd

OR

cd ~
SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My initial suggestion was to add the fully qualified oraenv path.  Also, I've seen one workaround by adding the profile to the cron line: "$HOME/.profile; /u01/scripts/somescript.sh"
Avatar of YZlat

ASKER

I changed . oraenv to . /usr/local/bin/oraenv


and now I am getting an error when trying to export ORACLE_HOME:


/home/oracle/Scripts/MyScript.ksh[16]: dbhome:  not found.



I checked /usr/local/bin and dhome exists there
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

>>I am getting an error when trying to export ORACLE_HOME

oraenv does this for you.

In your crontab script above the oraenv call:
export PATH=/usr/local/bin:$PATH
Avatar of YZlat

ASKER

/usr/local/bin is already in $PATH

I changed my code to:

ORAENV_ASK=NO
export ORACLE_SID=$1
export PATH=$ORACLE_HOME/bin:$PATH
. /usr/local/bin/oraenv
export ORACLE_HOME

but still getting the same error.

Btw, could you tell me what does ORAENV_ASK=NO do?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

thanks. So how should I modify my code?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

It ran, looks like it is working! Thank you!

So . oraenv exports ORACLE_HOME automatically?
>>So . oraenv exports ORACLE_HOME automatically?

Not 100% sure about exporting but it does set it for the rest of the script.  It also adds $ORACLE_HOME/bin to your PATH.

It sets up your ORAcle ENVironment.  Hence the name: oraenv.
Avatar of YZlat

ASKER

one more thing, if I run my script from crontab, I need to set my $PATH again, regardless what it is set to outside of crontab?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of YZlat

ASKER

Thanks so much for all your help!