change user and launch command

This is a discussion on change user and launch command within the solaris forums in Operating Systems category; Hi all, i need to change user in root script and launch commands. For example: #!/bin/bash su - john (in john environment) cd scripts go.sh (with john variables) exit in this case, the user became murex but next command after su - john goes in root user how can i do? i tried with: #!/bin/bash su - john...

Go Back   Database Forum > Operating Systems > solaris

Database Forums

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-28-2008, 10:00 AM
Default change user and launch command

Hi all, i need to change user in root script and launch commands. For
example:

#!/bin/bash
su - john
(in john environment)
cd scripts
go.sh (with john variables)
exit

in this case, the user became murex but next command after "su - john"
goes in root user

how can i do? i tried with:
#!/bin/bash
su - john <<- END
(in john environment)
cd scripts
go.sh (with john variables)
exit
END
but it doesn't work

thanks
Reply With Quote
  #2  
Old 08-28-2008, 11:31 AM
Default Re: change user and launch command

Patrick wrote:
> in this case, the user became murex but next command after "su - john"
> goes in root user


You need to review the 'su' manpage... in particular, the '-c' argument,
which acts much like -c when supplied to a shell.


su - john -c '/usr/bin/env'

However, be aware that it might not pick up environment settings from
the user's .profile and the like. (It probably will, but I've seen
cases where it didn't.) Be careful how much you assume.

--
Brandon Hume - hume -> BOFH.Ca, http://WWW.BOFH.Ca/
Reply With Quote
  #3  
Old 08-28-2008, 11:35 AM
Default Re: change user and launch command

Patrick schreef:
> Hi all, i need to change user in root script and launch commands. For
> example:
>
> #!/bin/bash
> su - john
> (in john environment)
> cd scripts
> go.sh (with john variables)
> exit
>
> in this case, the user became murex but next command after "su - john"
> goes in root user
>
> how can i do? i tried with:
> #!/bin/bash
> su - john <<- END
> (in john environment)
> cd scripts
> go.sh (with john variables)
> exit
> END
> but it doesn't work
>
> thanks


You can do this:
su - john -c "/scripts/go.sh"
Reply With Quote
  #4  
Old 08-28-2008, 11:40 AM
Default Re: change user and launch command

Patrick wrote:
> #!/bin/bash
> su - john
> (in john environment)
> cd scripts
> go.sh (with john variables)
> exit



man su:

To execute command with the temporary environment and per-
missions of user bin, type:

example% su - bin -c "command args"

or

su - user -c "cd scripts; ./go.sh"
Reply With Quote
Reply


Thread Tools
Display Modes



All times are GMT -4. The time now is 05:32 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Integrated by bbpixel2008 :: jvbPlugin R1013.368.1

Search Engine Friendly URLs by vBSEO 3.1.0
vB Ad Management by =RedTyger=
In an effort to better serve ads to our visitors, cookies are used on Mydatabasesupport.com. For more information, check out our Privacy Policy.