FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian User

 
 
LinkBack Thread Tools
 
Old 10-28-2008, 11:32 PM
"Star Liu"
 
Default how to execute a command as another user in one command?

currently i'm the root user, but I need to execute a command as
another user named postgres, I can do it in 2 commands, and it works
fine.
-----------
su postgres
postgres -D ~/data > ~/log/logfile 2>&1 &
-----------
but i hope I can do it in one command, so I tried this
---------------
su -c "postgres -D ~/data > ~/log/logfile 2>&1 &" postgres
----------------
but it doesn't work. what's wrong with it? or any other command to
realize it? thanks



--
I'm a debian user and a web
developer(XML+XSLT+AJAX+XHTML+CSS+PostgreSQL+MON O C#) in City of
Shanghai, China.
Welcome to add my IMs! (msn) starliu@live.com (xmpp) minxinjianxin@gmail.com
HomePage http://starliu dot 9966 dot com [It's only available when my
personal machine is running, on which it's hosted.]
 
Old 10-29-2008, 12:23 AM
Sam Leon
 
Default how to execute a command as another user in one command?

Star Liu wrote:

currently i'm the root user, but I need to execute a command as
another user named postgres, I can do it in 2 commands, and it works
fine.
-----------
su postgres
postgres -D ~/data > ~/log/logfile 2>&1 &
-----------
but i hope I can do it in one command, so I tried this
---------------
su -c "postgres -D ~/data > ~/log/logfile 2>&1 &" postgres
----------------
but it doesn't work. what's wrong with it? or any other command to
realize it? thanks





Try:

su - postgres -c "postgres -D ~/data > ~/log/logfile 2>&1 &"

Sam


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 10-29-2008, 12:25 AM
Chris Burkhardt
 
Default how to execute a command as another user in one command?

Star Liu wrote:
> currently i'm the root user, but I need to execute a command as
> another user named postgres, I can do it in 2 commands, and it works
> fine.
> -----------
> su postgres
> postgres -D ~/data > ~/log/logfile 2>&1 &
> -----------
> but i hope I can do it in one command, so I tried this
> ---------------
> su -c "postgres -D ~/data > ~/log/logfile 2>&1 &" postgres

What error does that give?

> ----------------
> but it doesn't work. what's wrong with it? or any other command to
> realize it? thanks

The sudo command is an alternative that comes to mind.

- Chris Burkhardt


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
 
Old 10-29-2008, 12:39 AM
"Star Liu"
 
Default how to execute a command as another user in one command?

On Wed, Oct 29, 2008 at 9:25 AM, Chris Burkhardt <chris@mretc.net> wrote:
> Star Liu wrote:
>> currently i'm the root user, but I need to execute a command as
>> another user named postgres, I can do it in 2 commands, and it works
>> fine.
>> -----------
>> su postgres
>> postgres -D ~/data > ~/log/logfile 2>&1 &
>> -----------
>> but i hope I can do it in one command, so I tried this
>> ---------------
>> su -c "postgres -D ~/data > ~/log/logfile 2>&1 &" postgres
>
> What error does that give?
thank you, the error says cannot find postgres command, so i change it to this:
su -c "/usr/lib/postgresql/8.3/bin/postgres -D ~/data > ~/log/logfile
2>&1 &" postgres
and it works now!


>> ----------------
>> but it doesn't work. what's wrong with it? or any other command to
>> realize it? thanks
>
> The sudo command is an alternative that comes to mind.
>
> - Chris Burkhardt
>
>
> --
> To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
>
>



--
I'm a debian user and a web
developer(XML+XSLT+AJAX+XHTML+CSS+PostgreSQL+MON O C#) in City of
Shanghai, China.
Welcome to add my IMs! (msn) starliu@live.com (xmpp) minxinjianxin@gmail.com
HomePage http://starliu dot 9966 dot com [It's only available when my
personal machine is running, on which it's hosted.]
 

Thread Tools




All times are GMT. The time now is 04:15 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org