What a n00b!

Running Commands as Another User in a Script

There's plenty of situations where you need to to open a shell to run something as a different user within a script. Scripts like the Zimbra start-stop scripts can't be run using sudo (Honestly, I don't know why and haven't questioned it). For my script, the root user doesn't have the zmcontrol utility in its path, so it had to actually spawn a shell as the zimbra user to run. Since it wasn't terribly obvious after a few minutes of googling, I decided to post how I did it. My example uses the zmcontrol utility which has to be run as the zimbra user:

su -l -c "zmcontrol start" zimbra

Comments

Comments powered by Disqus