Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 03-29-2009, 02:38 PM   #1
Registered: Jan 2009
Location: USA
Distribution: Fedora 14 / Slackware 13.1
Posts: 85

Rep: Reputation: 20
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.

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?
Old 03-29-2009, 02:50 PM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
su greg -c "mpdscribble -v file.txt"
Old 03-29-2009, 03:11 PM   #3
Registered: Jan 2009
Location: USA
Distribution: Fedora 14 / Slackware 13.1
Posts: 85

Original Poster
Rep: Reputation: 20
Duh! Thanks, should've remembered the -c option.


bash, root

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Root user check in bash script doesn't work tawalker Programming 6 12-18-2011 03:06 AM
Running functions in bash script as another user with su pwc101 Programming 5 12-13-2008 09:19 AM
detecting root user in a bash script radiodee1 Programming 2 11-30-2008 06:18 AM
Getting bash script files to run as root user helptonewbie Programming 5 04-13-2007 09:09 PM
bash script - open new window running a command zippity Linux - Newbie 1 07-13-2004 11:16 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:42 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration