execute command as different user
I am running a script as root, and need to execute a few commands as another user from within the script. I have tried enclosing the commands in both parenthesis and curly brackets such as the following:
{ su <username>; source .bash_profile; <command1>; <command2> } The problem is that commands 1 & 2 are execute as root, so the user was not changed by the su command. Actually, it appears as if it was changed, but that the commands following the su command were not executed in the correct shell. Is there any way to accomplish what I need? Thanks. |
$su
Password: #su foo -c whoami foo As you can see i ran a command as foo. I guess u'll have to run individual commands instead of group HTH |
Enclose in quotes: su <username> -c 'a; b; c' ?
|
All times are GMT -5. The time now is 05:36 PM. |