1755042 Members
3568 Online
108828 Solutions
New Discussion юеВ

scripting

 
SOLVED
Go to solution
malay boy
Trusted Contributor

scripting

Guru's,
what is the different between :

1)su -c '$ORACLE_HOME/bin/svrmgrl' << EOT
connect internal
startup
exit
EOT
2)su - c "$ORACLE_HOME/bin/svrmgrl << EOT
connect internal
startup
exit
EOT"

when I run 1) I only got :

svrmgrl>
#

It not startup the database at all.

but with 2) is connect and start the database.

any input are appreciate.I have span about 1 day Saturday to rectify this problem.

regards
mB
There are three person in my team-Me ,myself and I.
2 REPLIES 2
John Poff
Honored Contributor

Re: scripting

Hi mB,

Your first example switches to the user but without the '-' option the user's .profile and other environment settings aren't executed, so you don't get the normal environment. For the second example, you used the '-' option and got the full environment as if you had logged in as the user. The 'c' option should probably be '-c' which tells the shell to read the commands from the string you passed to it.

This may be what you are after:

su - -c "$ORACLE_HOME/bin/svrmgrl <...
etc.

JP
curt larson_1
Honored Contributor
Solution

Re: scripting

I'm sure you can just read the man page for su for a better explaination for the following:
1) not having a username
2) have a - -c or just a -c

i would suppose you left out the username in this case and the - c in #2 is just a typo.

the main difference is with the single quotes (') and the double quotes (").

in #1, the use of the single quotes passes $ORACLE_HOME/bin/svrmgrl to be executed as the command, ie the variable $ORACLE_HOME isn't substituted until after your have changed users. and being the second (') occurs before the <<, the shell creates the heredoc file and opens it as standard input.

in #2, the use of the double quote causes variable subtitution on $ORACLE_HOME to occur before the user is switched, ie the value of $ORACLE_HOME in the current environment will be used instead the the value of $ORACLE_HOME in the new users environment. and the second double quotes occurs at the end of the heredoc, this causes your heredoc to become commandline arguments to svrmgrl instead of becoming a heredoc and read in as standard input. and of course this means #1 works and #2 doesn't.

su user -c 'command' <<
is the same as
su user -c "$command' <<
if in the current environment, $command=command.

su user -c '$command' <<
is the same as
su user -c "\$command" <<

and i'd suspect your wanting to use something like
su - someuser -c '$ORACLE_HOME' << your here doc.