Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

change user and launch command

0 views
Skip to first unread message

Patrick

unread,
Aug 28, 2008, 9:00:22 AM8/28/08
to
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

hume.sp...@bofh.ca

unread,
Aug 28, 2008, 10:31:39 AM8/28/08
to
Patrick <patrick...@gmail.com> 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/

D3vN0ll

unread,
Aug 28, 2008, 10:35:30 AM8/28/08
to
Patrick schreef:

You can do this:
su - john -c "/scripts/go.sh"

Oscar del Rio

unread,
Aug 28, 2008, 10:40:26 AM8/28/08
to
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"

0 new messages