LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 03-29-2009, 02:38 PM   #1
camphor
Member
 
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.

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

Rep: Reputation: 108Reputation: 108
Code:
su greg -c "mpdscribble -v file.txt"
 
Old 03-29-2009, 03:11 PM   #3
camphor
Member
 
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.
 
  


Reply

Tags
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


All times are GMT -5. The time now is 07:56 PM.

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