Operating System - HP-UX
1850938 Members
2208 Online
104056 Solutions
New Discussion

Re: Using su command from a script

 
Robert DJ
Frequent Advisor

Using su command from a script

Hi,

I'd like to know how we can use the su command thro a script.......any syntax...

thank you.

Robs
Robert DJ
6 REPLIES 6
Steven E. Protter
Exalted Contributor

Re: Using su command from a script

Shalom Robert,

Several ways to do it.

su - username -c "commandline"

That is a very common way for a root cron or startup job to become user username and execute whats between the quotes using that users environment.

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
Robert-Jan Goossens_1
Honored Contributor

Re: Using su command from a script

Hi Rob,

example of the command we use in a rc2.d start oracle script

su - oracle -c /app/oracle/admin/bin/server_start

Best regards,
Robert-Jan
Robert DJ
Frequent Advisor

Re: Using su command from a script

Hi,

Thank you for the replies....

trying to execute multiple commands using the su ...

e.g,
su - user1 -c "ksh"
and then i need to run a script or command under this shell like,
my startup scripts or commands.....

Thank you once again.

Regards,
Robs
Robert DJ
Luk Vandenbussche
Honored Contributor

Re: Using su command from a script

Hi write a script, fe sucript with contains

ksh
script

Then exucute

su - user1 -c "suscript"
saju_2
Respected Contributor

Re: Using su command from a script

Hi robert

If u want to run a script with name "script1.sh" with oracle id , you can use

su - oracle -c "/home/oracle/script1.sh

Regards
CS
Robert DJ
Frequent Advisor

Re: Using su command from a script

I tried the options but didnt work so ive re- wrote the script to to work on tcsh shell and then run my specific command.

Thank you once again for the help.

Robs
Robert DJ