LinuxQuestions.org
Visit Jeremy's Blog.
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, 09: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, 10: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, 10:03 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,417
Blog Entries: 55

Rep: Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627Reputation: 3627
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 07:10 AM
remote command execute telnet with 1 command MPowers Linux - Networking 2 06-30-2005 06:31 AM
boot script execute command as non-root user wampfler Linux - Security 7 09-24-2004 04:56 AM
Execute a command as another user mpgram Linux - Newbie 6 06-08-2004 11:45 PM
Ordinary user can execute the "halt" command ederts Linux - Newbie 7 05-24-2001 11:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:53 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
Open Source Consulting | Domain Registration