Operating System - HP-UX
1849401 Members
8578 Online
104044 Solutions
New Discussion

Re: Exit from su in a script

 
SOLVED
Go to solution
yc_2
Regular Advisor

Exit from su in a script

Hi,

In a script, how do I exit from:

su - user -c "command"

and continue other operations within the script.

Thanks in advance,
YC
7 REPLIES 7
Murray Jones
Advisor

Re: Exit from su in a script

Unfortunately I don't have a system at hand to test this. Can you place the command in the background in the script?:

su - user -c "command" 2>&1 &

Cheers,

Murray
yc_2
Regular Advisor

Re: Exit from su in a script

Hi Murray,

The subsequent operations has to be done after the completion of the "su" command. How to go about it with your suggestion ?


Rgds,
YC
Manju Kampli
Trusted Contributor
Solution

Re: Exit from su in a script

when you do su with -c "command" option, the su will exit as soon as the command finishes its job. put your additional command next to it and things should work.

I have a script which start the oracle listener demon and then start the oracle database in the same script
su - oracle -c 'lsnrctl start listener'
su - oracle -c '/oravl01/oracle/dba/util/start_ctx.sh'
su - oracle -c '/oravl01/oracle/8.0.5/ows/3.0/bin/owsctl start wrb'
. ~oracle/.profile
/oravl01/oracle/8.0.5/ows/3.0/bin/owsctl start www
su - taskman -c '/opt/OV/taskman/bin/ptm start DEV'

hope this answers your question
Never stop "LEARNING"
James R. Ferguson
Acclaimed Contributor

Re: Exit from su in a script

Hi:

When you complete the command or script specified with the -c option, you will be returned to the script and environment from which you came. No special action is necessary.

...JRF...
CHRIS_ANORUO
Honored Contributor

Re: Exit from su in a script

When the command specified runs and terminates, it goes to the next line in yur script. It does not need an exit sentence to terminate its process of execution.
When We Seek To Discover The Best In Others, We Somehow Bring Out The Best In Ourselves.
Murray Jones
Advisor

Re: Exit from su in a script

Yeh, what they said.

Wot, still no points assigned?....

Cheers,

Murray

Re: Exit from su in a script

Try this :


su - user -c "command" 2>&1 &

wait # wait all backgrownd commands

#next command