Operating System - HP-UX
1834149 Members
3869 Online
110064 Solutions
New Discussion

su - id -c command and only return the result of the command

 
SOLVED
Go to solution
Geoff Wild
Honored Contributor

su - id -c command and only return the result of the command

Okay - this should be easy - but I can't figure it out.

For example:

su - oraadm -c "echo \$ORACLE_HOME"

I only want to return the $ORACLE_HOME variable. I don't want all the "Copyright" information...

Basically, in a script I want to set the ORACLE_HOME variable to that of another user so I can launch a program.

Thanks...Geoff
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.
4 REPLIES 4
curt larson_1
Honored Contributor
Solution

Re: su - id -c command and only return the result of the command

all the copyright stuff is part of the login process, so your always going to get that with su -

have you tried something like

su - oraadm -c "print oracle_home = \$ORACLE_HOME" | awk '
/^oracle_home/ {print $3;}'
Michael Denney
Valued Contributor

Re: su - id -c command and only return the result of the command

If you are running your script as root, you could simply source the .profile of the oraadm user. Example to put all the environment of oraadm user into your script:

. ~oraadm/.profile



Geoff Wild
Honored Contributor

Re: su - id -c command and only return the result of the command

Curt - very close - had to do it like this:

su - iqaadm -c "printf oracle_home=\$ORACLE_HOME" |awk -F= '/^oracle_home/ {print $2;}'

as print not found.

Thanks!
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.
Geoff Wild
Honored Contributor

Re: su - id -c command and only return the result of the command

Michael - for various reasons, I won't source the .profile. I meant to mention that in the question.

Thanks...Geoff
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.