Simpler Navigation for Servers and Operating Systems - Please Update Your Bookmarks
Completed: a much simpler Servers and Operating Systems section of the Community. We combined many of the older boards, so you won't have to click through so many levels to get at the information you need. Check the consolidated boards here as many sub-forums are now single boards.
If you have bookmarked forums or discussion boards in Servers and Operating Systems, we suggest you check and update them as needed.
cancel
Showing results for 
Search instead for 
Did you mean: 

Running db admin scripts as root

SOLVED
Go to solution
Joe Robinson_2
Super Advisor

Running db admin scripts as root

I'm working on including my Oracle admin scripts within my 'pre' and 'post' scripts (using Omniback II) to simplify my backups but am hitting some road blocks due to the Oracle environment not being able to run server mgr. as root. I'd be grateful if anyone has a simple suggestion how I can run those scripts (owned by the Oracle account) as root...

Thanks in advance!
6 REPLIES
Steven E. Protter
Exalted Contributor
Solution

Re: Running db admin scripts as root

The script can have them like this:

/usr/bin/su - oracle -c "command"

Run out of root cron, this will run without a password prompt.

It is never a good idea to run databse scripts as root.

It can tie up shared memory resources, lock your database, all kinds of ugly things.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Joe Robinson_2
Super Advisor

Re: Running db admin scripts as root

good one...I use that for the few times when I'm doing support on the floor and need to run a command as a different user (different from who I am working with) and walk away! Thanks for the idea!
Steven E. Protter
Exalted Contributor

Re: Running db admin scripts as root

Joe, how about a few points for helping????

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Pete Randall
Outstanding Contributor

Re: Running db admin scripts as root

Steven,

You're shameless!

;^)


Pete


Pete
A. Clay Stephenson
Acclaimed Contributor

Re: Running db admin scripts as root

There is a potential problem with using
/usr/bin/su - oracle -c "command"
rather than
/usr/bin/su oracle -c "command".

I know that you want to load Oracle's environment var's (ORACLE_HOME,ORACLE_SID,..) but the problem is that oracle's .profile contains statements like tset, tabs, tput ... which expect an interactive environment --- which you ain't. You can surround all those with
if [ -t 0 ]
then
tset
stty
tabs
fi

but a better way is to create a file (oraenv.sh) that sets and exports all those variables and then let your script AND oracle's .profile source this file.

e.g.
. /usr/local/bin/oraenv.sh

This will ensure that the environment is setup but not hang because no interactive environment is in play. Your oraenv.sh must not contain an exit or return statement because this would actually exit the shell because sourced files are not started as a separate process.


If it ain't broke, I can fix that.
Steven E. Protter
Exalted Contributor

Re: Running db admin scripts as root

A Clay is as always right.

My solution assumes that the oracle environment is correct.

The script called by the command section needs to call the correct oracle environment for the database to be used. ORACLE_HOME, ORACLE_SID and other required variables MUST be set or the script will fail.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com