Operating System - HP-UX
1819904 Members
2472 Online
109607 Solutions
New Discussion юеВ

Re: How to Su to Oracle, execute command and exit in a script?

 
SOLVED
Go to solution
Shaun Aldrich
Frequent Advisor

How to Su to Oracle, execute command and exit in a script?

Hello Everyone,

I have tried within a 3 line script to do the following:-

su - oracle
pwd
exit

While executing the script the first line suceeds, as it will su into oracle but the does not execute the pwd command and exit.

If I do this through the command line manually it works. For some reason if you execute these three lines in a simple script it will stop after the first line.

Any ideas???

Thanks for your help.

Shaun Aldrich
SAldrich@chaptersinc.com
4 REPLIES 4
John Palmer
Honored Contributor
Solution

Re: How to Su to Oracle, execute command and exit in a script?

Try

su oracle -c "pwd; etc..."

don't use the - argument from a script as it causes the profile scripts to be executed. See a recent thread on this issue.
James R. Ferguson
Acclaimed Contributor

Re: How to Su to Oracle, execute command and exit in a script?

Shaun:

You cannot provide the password to the su within the script. You will always be prompted interactively.

If you are root, you can write:

# su - oracle -c
This will run
...JRF...
Stefan Farrelly
Honored Contributor

Re: How to Su to Oracle, execute command and exit in a script?


If you simply go su - oracle you now log in as oracle, it wont run the last 2 lines of your script until you do an exit command. The - sign means actually log in as that user. Not what you want for a script unless you add the -c option.

I think what you really want to do is either;

1. su - oracle - c ""

2. su oracle Then you can run commands as oracle, eg. dbstart, dbshut (but dont forget to source oracles .profile first (. ~oracle/.profile)

Im from Palmerston North, New Zealand, but somehow ended up in London...
Tom Danzig
Honored Contributor

Re: How to Su to Oracle, execute command and exit in a script?

Try:

su - oracle <pwd
exit
EOD