1748252 Members
3938 Online
108760 Solutions
New Discussion юеВ

Shutdown Oracle

 
P-Dicky
Frequent Advisor

Shutdown Oracle

Good Morning,

I am trying to script an Oracle shutdown (10g on 11.23).. Here are the commands I would use just as the user to do so.

sql
Connect /as sysdba
Shutdown immediate;
Exit;

So I was planning on doing this from cron so I would su - user and then have that above in the script. Thing of it is when I try it the sql command never works? I can't seem to figure out where it is gettign the path from. I have checked the users .profile which then has a reference to another .profile and it kind of goes on and on. If the command works from the users prompt should it not work if the user is running it via script? Is it something to do with the su?

Thank you
Paul

su - user sql
ksh: sql: cannot open

su - user
sql
Works okay?
4 REPLIES 4
Murat SULUHAN
Honored Contributor

Re: Shutdown Oracle

Hi P-Dicky

you must manipulate following script to run in HP-UX

http://www.oracle-base.com/articles/linux/AutomatingDatabaseStartupAndShutdownOnLinux.php


Best Regards
Murat

Murat Suluhan
James R. Ferguson
Acclaimed Contributor

Re: Shutdown Oracle

Hi Paul:

Remember that the environment for startup and shutdown scripts as well as the environment for a 'crontask', is very sparse. For instance, the PATH consists, by default, of only '/usr/sbin:/usr/bin:/sbin'.

There is never any harm in using absolute paths in your startup and cron'd scripts. You can easily find where your commands live with :

# whereis sql

(when the command is in your PATH; or):

# find / -type f -name sql

Your startup and shutdown script will be executed as root, so you will want to do something like:

# su - oracle -c "nohup ${ORACLE_HOME}/bin/dbshut &" > /dev/null 2>&
1

When a command works from a user's environment at commandline but not as a part of a 'crontab' or startup/shutdown script, generally something is missing from the environment. Using 'su - username' as shown cause the users' login profile to be sourced (read). This is one way to populate the necessary environmental variables. Another way is to simply declare what you need or source an independent file of variables in your script.

If you run:

# env

...after you login as the working user at commandline, you will see the environment that works.

Regards!

...JRF...
P-Dicky
Frequent Advisor

Re: Shutdown Oracle

Sorry still stuck...

$ whereis sql
sql:
$ echo $sql

$

I have tried doing a find but still can not find anything that result in the sql> prompt.

As for the env it is not much help as it seems there are about 1000 entries. Even searching the results for sql show nothing.

I have heard it is better to shutdown oracle from within sql then to use the shutdb start db scripts?
James R. Ferguson
Acclaimed Contributor

Re: Shutdown Oracle

Hi (agani):

> I have tried doing a find but still can not find anything that result in the sql> prompt.

I believe that you want 'sqlplus'. Make sure, too, that the ${ORACLE_SID} environment variable is set.

> I have heard it is better to shutdown oracle from within sql then to use the shutdb start db scripts?

This is a database, not a language question.

Regards!

...JRF...