1834327 Members
2130 Online
110066 Solutions
New Discussion

Help writng script

 
Eric Shupe
Occasional Contributor

Help writng script

I am trying to write a script to shutdown a database so it can be incorporated into my backup. When I type the following commands at the command line as root it works no problem:

# su - oracle
$ csh
$ dserv_shutdown
$ exit
$ exit

when I put these commands into a script it seems to only execute the first line. Am I doing soemthing wrong or do I need to go about doing this a different way??

Thanks for any advice.
11 REPLIES 11
Neil Haslum_1
New Member

Re: Help writng script

try putting those commands after su - oracle and running
su - oracle -c <script>
Neil Haslum_1
New Member

Re: Help writng script

in english this time:
try putting those commands after su - oracle in a script and running
su - oracle -c <script>
Allan Pincus
Frequent Advisor

Re: Help writng script

Your first command is switching users, so it probably needs a password authentication, and is not getting it. You need to log into oracle first, or authenticate the user through the script.

-Allan

Fred Martin_1
Valued Contributor

Re: Help writng script

Switching shells is the problem, I think. The 'csh' line for example, opens a new environment space that knows nothing about the previous one, including the script that may be running. Do you need to be in csh (or, do you need to be user oracle) to shut down the database?

If your backup script runs as root, would it do to just have the dserv_shutdown line in the script directly?
fmartin@applicatorssales.com
Eric Shupe
Occasional Contributor

Re: Help writng script

In order to shutdown the database it must be user oracle and it must be in the C shell. root cannot stop it. there are a bunch of variables set within user oracle.
Keith Johnson
Valued Contributor

Re: Help writng script

We have a "master script" to run our Oracle DB backkups. Our cron entry looks like:

00 02 * * 0-6 /script/name > /output/log 2>&1

Within the script we call several other scripts, including the one that actually shuts the DB down and performs the backup. It is called like:

/bin/su - oracle7 - c "/script/name1"

Works pretty well for us.

HTH

KJ

No matter where you go...there you are.
Keith Johnson
Valued Contributor

Re: Help writng script

Forgot to mention that we run this from the root cron.

KJ
No matter where you go...there you are.
Andreas Voss
Honored Contributor

Re: Help writng script

Hi,

this should work:

su - oracle -c "/bin/csh -c dserv_shutdown"

Regards
Shahul
Esteemed Contributor

Re: Help writng script


Hi

Once U do su, then U are in different environment. Actually, the commands after #su - oracle are not taking in to effect. U can see the outputs in the old environment.

Solution is either U do like this

#su - oracle -c "csh dserv_shutdown"

Or

Create a script with the commands except su command and then

#su - oracle -c "cat /tmp/script"

This both will work.

Best of luck
Shahul
Wodisch
Honored Contributor

Re: Help writng script

Hi,

how about:

su - oracle <csh -c dserv_shutdown
EOF

That should do the trick...

Regards,
Wodisch
Geoff Wild
Honored Contributor

Re: Help writng script

A good way to do this is like:

First create a script in oracle's path - say oracle_stop.

Then, from your backup server:

`/bin/su - oracle -c "oracle_stop"`
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.