LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Running a command as another user in a bash script ran as root? (http://www.linuxquestions.org/questions/programming-9/running-a-command-as-another-user-in-a-bash-script-ran-as-root-715320/)

camphor 03-29-2009 02:38 PM

Running a command as another user in a bash script ran as root?
 
Hello all! I've written a short bash script for use when I'm at home that brings a network interface up, sets a few options, and starts a few programs. This needs to be run as root so that DHCP can be configured correctly, etc. It works great, but the problem I've run into is not being able to run a shell command as another user from within the bash script.

Code:

echo `su greg | mpdscribble && exit`
This is what I have right now, and it does start mpdscribble, but I have to manually exit out of the su part before the rest will finish. Is there an easier way to go about this, or is my grammar just wrong?

Hko 03-29-2009 02:50 PM

Code:

su greg -c "mpdscribble -v file.txt"

camphor 03-29-2009 03:11 PM

Duh! Thanks, should've remembered the -c option.


All times are GMT -5. The time now is 04:34 PM.