homer_3 |
03-14-2014 09:01 AM |
Executing command in bash script as a different user?
I'm running a bash script as root and want to execute a command in the script as a different user. The lines of interest in the script are below. If I copy and paste the results of the echo to my command line, the script runs as the other user. But If I run the script, the command never executes and no errors are logged to the screen.
Code:
echo "su otheruser -c '$COMMAND'"
$(su otheruser -c '$COMMAND')
I've also tried
Code:
echo "su otheruser -c '$COMMAND'"
su otheruser -c '$COMMAND'
|