1829581 Members
4264 Online
109992 Solutions
New Discussion

su to root in a script

 
Morris Makuch
Advisor

su to root in a script

Can anyone tell me how to su to root in a script? I have a oracle script and want to shutdown my service guard package (which is oracle) but cannot find the right syntax for su to root to shutdown my package

Thanks
7 REPLIES 7
Michael Tully
Honored Contributor

Re: su to root in a script

Oracle is not my area of expertise, but if your running a script as oracle and you have to su to root, then a password or setuid wrapper has to be used. You could also consider using 'sudo' You can get it from here:

http://hpux.connect.org.uk/hppd/hpux/Sysadmin/sudo-1.6.6/
Anyone for a Mutiny ?
A. Clay Stephenson
Acclaimed Contributor

Re: su to root in a script

You will have an easier time of this and not be prompted for a passwd if you turn the world around and run your script as root and su to oracle. You do not want to do a su - oracle but rather a plain su oracle command. You should load all the environment vars from a sourced file that sets and exports these variable via a command like . /usr/local/bin/oraenv.sh. THere must be no exit or return statements in this sourced file. The smart way to do this is to also source this same file in oracle's .profile. You want to avoid any commands in your su oracle which expect an interactive environment which the normal .profile does.
If it ain't broke, I can fix that.
Niraj Kumar Verma
Trusted Contributor

Re: su to root in a script

Hi,

I think you can achive what you are trying to achive using sudo in better way.

-Niraj
Niraj.Verma@philips.com
Ulrich Deiters
Frequent Advisor

Re: su to root in a script

If you have ssh installed, enter
ssh HOST -l root "MY COMMAND"

This also works inside scripts. For each non-root user allowed to use your script you have to store the public ssh key in root's ssh directory (/.ssh2) .
Jean-Luc Oudart
Honored Contributor

Re: su to root in a script

running a comand as root is one of the regular questions.
check this link
http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x4b0857bd90a9d611abdb0090277a778c,00.html

Jean-Luc
fiat lux
Systeemingenieurs Infoc
Valued Contributor

Re: su to root in a script

I would also settle for sudo. I was wondering if setprivgrp(1M) might be an option. Perhaps you can specifiy that oracle can change his ruid to root. Never tried it. Anyone else ?
A Life ? Cool ! Where can I download one of those from ?
Leif Halvarsson_2
Honored Contributor

Re: su to root in a script

Hi
I agrree with Clay, this is better to do as root user. If uou add root to the DBA group (recommended) you can shut down Oracle as root user too.