Pages

Wednesday, December 24, 2014

run command as another user in linux

run command as another user in linux

Say I want to run a linux command as another user, How to do it ?
su command can be used to run command as another user in linux.

Syntax:

 su - <UserName> -c "Command"

Example:

The following example will execute a SQL Query as postgres user.
This command is run as root user.

su - postgres -c "psql -d HQ -c \"update EAM_ACTION SET classname='org.hyperic.hq.bizapp.server.action.email.EmailAction' \"" 

I got this solution from here.
http://www.cyberciti.biz/open-source/command-line-hacks/linux-run-command-as-different-user/

No comments:

Post a Comment