LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices



Reply
 
Search this Thread
Old 06-02-2003, 10:19 AM   #1
kilobravo
LQ Newbie
 
Registered: Feb 2002
Posts: 18

Rep: Reputation: 0
execute command as different user


I am running a script as root, and need to execute a few commands as another user from within the script. I have tried enclosing the commands in both parenthesis and curly brackets such as the following:

{ su <username>; source .bash_profile; <command1>; <command2> }

The problem is that commands 1 & 2 are execute as root, so the user was not changed by the su command. Actually, it appears as if it was changed, but that the commands following the su command were not executed in the correct shell. Is there any way to accomplish what I need?

Thanks.
 
Old 06-02-2003, 11:02 AM   #2
nikhiljosh
Member
 
Registered: Jun 2001
Posts: 126

Rep: Reputation: 16
$su
Password:
#su foo -c whoami
foo

As you can see i ran a command as foo.
I guess u'll have to run individual commands instead of group
HTH
 
1 members found this post helpful.
Old 06-02-2003, 11:03 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,758
Blog Entries: 54

Rep: Reputation: 2975Reputation: 2975Reputation: 2975Reputation: 2975Reputation: 2975Reputation: 2975Reputation: 2975Reputation: 2975Reputation: 2975Reputation: 2975Reputation: 2975
Enclose in quotes: su <username> -c 'a; b; c' ?
 
  


Reply


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to execute iptables command by the user apache ??? Bassam Linux - Security 2 10-28-2005 08:10 AM
remote command execute telnet with 1 command MPowers Linux - Networking 2 06-30-2005 07:31 AM
boot script execute command as non-root user wampfler Linux - Security 7 09-24-2004 05:56 AM
Execute a command as another user mpgram Linux - Newbie 6 06-09-2004 12:45 AM
Ordinary user can execute the "halt" command ederts Linux - Newbie 7 05-24-2001 12:18 PM


All times are GMT -5. The time now is 09:01 AM.

Main Menu
Advertisement
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