Operating System - HP-UX
1754920 Members
3031 Online
54826 Solutions
New Discussion юеВ

Re: Script not working in Cron

 
SOLVED
Go to solution
John Palmer
Honored Contributor

Re: Script not working in Cron

Here is a simple script to set-up an Oracle environment:-
-------------cut here-------------
export ORACLE_SID=${1:-????}
ORAINFO=$(grep "^${ORACLE_SID}:" /etc/oratab 2>/dev/null)
if [[ -n ${ORAINFO} ]];
then ORAINFO=${ORAINFO%%\#*}
IFS=:
set ${ORAINFO}
unset IFS

export ORACLE_HOME=${2}
export PATH=${PATH}:${ORACLE_HOME}/bin
export SHLIB_PATH=${ORACLE_HOME}/lib

else print "No info in /etc/oratab for SID ${ORACLE_SID}"
ORACLE_SID=""
fi
------------cut here---------------------

Substitute whatever SID you want as the default in place of ????.

If you put this script into a directory that is already on your path then add the following line to your main script:-
. ora_env
or if the directory is not included in PATH then:-
. /

PATH must contain the directory name '$ORACLE_HOME/bin' not the name of the command such as '$ORACLE_HOME/bin/sqlplus'.

What I meant by a 'subscript' was using the '. ' command to execute a script within your current script not as a separate process (commonly known as 'dotting' the script).

Regards,
John
Rainer von Bongartz
Honored Contributor

Re: Script not working in Cron


Beverly,


at is your standard unix command to execute jobs at
a specific time

i.e.

at 22:30
/ora0/oracle/SQL/anal_schemas


this will create your job /var/spool/cron/atjobs/*.a

you can look at this file and will see what environement
variables are set.

By the way:
if this job works you can use the job xyz.a and start this
through cron. you will be sure then that all varaibales are set.

See also: man at
He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
Beverly Wixon
Advisor

Re: Script not working in Cron

To John Palmer. Wow! Our definitions of simple are way different. :) I'm trying it though. Isn't this (following) basically the same, except that it's missing the $ORACLE_HOME/bin directory.

ORACLE_SID='repp'
ORACLE_BASE='/ora0/oracle/app/oracle/product'
ORACLE_HOME='/ora0/oracle/app/oracle/product/8.0.5'
export ORACLE_HOME ORACLE_SID ORACLE_BASE
PSWD=`cat /ora0/oracle/passwd/system`
sqlplus system/$PSWD@repp @$HOME/SQL/anal_schemas.sql


To Rainer: Thanks. I don't have the permissions to run the at command, so I sent your reply to the sysadm asking her to run it.

Thanks a bunch.
John Palmer
Honored Contributor

Re: Script not working in Cron

Yes it's doing the same thing but it avoids hard coding pathnames into your scripts. When you come to upgrade Oracle, just amend the entry in /etc/oratab and voila all your scripts still work!

Regards,
John
Beverly Wixon
Advisor

Re: Script not working in Cron

To John Palmer -- Oh. I think I get it. This is a totally separate script, not just variables set at the start of every script (as it is done here). Then, after upgrading the rdbms, I would only have to edit one file (the etc you mentioned). And, since we are upgrading databases, this makes sense to me. Thanks for the info. It may make things much easier for me in the future -- when I actually write a Unix scripts. Unfortunately, right now, I still need to figure out why this one (which I did not write) won't work. Any ideas after looking at the scripts themselves.
John Palmer
Honored Contributor
Solution

Re: Script not working in Cron

I think that you're just missing
PATH=${PATH}:${ORACLE_HOME}/bin
Beverly Wixon
Advisor

Re: Script not working in Cron

Okay, John. I have added the following lines and have it set to test in a few minutes. Thanks, again.

ORACLE_PATH='/ora0/oracle/app/oracle/product/8.0.5/bin'

export PATH=$ORACLE_PATH
export SHLIB_PATH=$ORACLE_HOME/lib
John Palmer
Honored Contributor

Re: Script not working in Cron

You need
PATH=$PATH:$ORACLE_PATH

otherwise you will lose your normal PATH settings (/usr/bin etc)
Beverly Wixon
Advisor

Re: Script not working in Cron

PATH=${PATH}:${ORACLE_HOME}/bin

or

PATH=$PATH:$ORACLE_PATH

I'm sorry, but I am getting very confused.
John Palmer
Honored Contributor

Re: Script not working in Cron

PATH=${PATH}:${ORACLE_HOME}/bin
is preferable.

${PATH} is another way of writing $PATH.

PATH=$PATH:$ORACLE_PATH gives the same result because you have already set ORACLE_PATH to '/ora0/oracle/app/oracle/product/8.0.5/bin'

Regards,
John