Execute command as another user in bash scriptBy neokrates, written on May 4, 2010 |
bash snippet |
- neokrates
- Email: uwarov@yahoo.com
- Website: http://www.thinkplexx.com
- Join date: 05-31-09
- Posts: 20
Rate it
Ad
Poll
Loading ...
Most popular search terms:
Stats
-
Since publication, this page was visited 1282 time(s).
su can execute commands under other user without interaction.
Example:
Run whoami;ls -all as $ANOTHER_USER:
su $ANOTHER_USER -l -c "whoami;ls -all"
Remark: Sometimes execution fails due the different environment. In my case, I want the same environment as I had if I changed user interactively: -l.
Here is general su help:
me@my-host:~/ # su --help Usage: su [options] [LOGIN] Options: -c, --command COMMAND pass COMMAND to the invoked shell -h, --help display this help message and exit -, -l, --login make the shell a login shell -m, -p, --preserve-environment do not reset environment variables, and keep the same shell -s, --shell SHELL use SHELL instead of the default in passwd
|
TAGS
|
|
SOCIAL
|


















