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: 

root, oracle,rdbms and sqlplus

Scott E Smith
Frequent Advisor

root, oracle,rdbms and sqlplus

We are trying to run an sql query as root to get the number of current sessions on the database. Normally we run this as oracle but now we need it as root for monitoring. I seem to be having environment issues as the commands do not work....
su oracle -c /../../..sqlplus sess.sql ....
I get sqlplus not found even after setting path etc.....

PATH=$PATH;/opt/oracle/8.1.7/bin/;.
ORACLE_SID=$1
ORACLE_SCRIPT=/opt/oracle/admin/script
ORACLE_HOME=/opt/oracle/8.1.7
export ORACLE_SID
export ORACLE_HOME
export SESSLOC=/opt/oracle/admin/script/sess.sql
export SQL=/opt/oracle/admin/script/sqlplus.sh

SES=`su oracle "$SQL system $SESSLOC |grep rows |cut -d " " -f 1"`

echo "The number of active sessions is $SES"
Any ideas? Thanks.
5 REPLIES
Pete Randall
Outstanding Contributor

Re: root, oracle,rdbms and sqlplus

As Oracle, do "env |grep -i oracle" and compare this against the same output when logged in as root. There's got to be something missing from root's env.


Pete


Pete
Volker Borowski
Honored Contributor

Re: root, oracle,rdbms and sqlplus

Try "su - oracle ....."

the "-" tells su to execute the login environment.

This helps (no hope needed !)
Volker
prasad_15
Advisor

Re: root, oracle,rdbms and sqlplus

LD_LIBRARY_PATH ??

A. Clay Stephenson
Acclaimed Contributor

Re: root, oracle,rdbms and sqlplus

You do not want to use su - oracle to read Oracle's .profile unless you surround all the interactive commands like tset, stty, and tabs with
if [[ -t 0 ]]
then
...
...
fi

The better way is to create a file (e.g. /usr/local/bin/oraenv.sh) and let your script and oracle's .profile source it via
. /usr/local/bin/oraenv.sh

This will insure that both your scripts and oracle's .profile will use exactly the same environment. NOTE: This sources file must not contain an exit or return statement.

Your specific problem is that you used semicolons rather than colons in the construction of your PATH.
If it ain't broke, I can fix that.
twang
Honored Contributor

Re: root, oracle,rdbms and sqlplus

I extracted some code from our auto-shutdown
oracle database script:

if [ "$LOGNAME" = "root" ]
then
echo "User root shells to oracle"
/usr/bin/su - oracle -c "/usr/contrib/bin/shut.oracle"
exit 1
fi