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
Which virtualization is used on your Enterprise?
- We don't use virtulization (90%, 9 Votes)
- VM Ware (10%, 1 Votes)
- Virtual Box (0%, 0 Votes)
- Parallels (0%, 0 Votes)
- coLinux (0%, 0 Votes)
- Xen (0%, 0 Votes)
- OpenVZ (0%, 0 Votes)
- Something else (0%, 0 Votes)
Total Voters: 10
Loading ...
Most popular search terms:
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
|


















