Operating System - HP-UX
1753823 Members
9182 Online
108805 Solutions
New Discussion юеВ

exec command in script from another user

 
SOLVED
Go to solution
Chartier Jerome
Frequent Advisor

exec command in script from another user

Hi all,

In a shell script, I would like to launch a command under another user account (sudo).
For example, in a root cron table, launch a script which calls as well oracle and root scripts .

Thanks in advance for your help

Cheers

J??r??me
J@Y
2 REPLIES 2
Mark Greene_1
Honored Contributor
Solution

Re: exec command in script from another user

You can use this :

su - [user] -c "commands"

to launch commands from a script or cron to be run as a different user. You can add logging to capture errors from the su like this:

su - [user] -c "commands" >logfile 2>&1

and like this to log the commands:

su - [user] -c "commands >cmd_logfile 2>&1"

or like this for both:

su - [user] -c "commands >cmd_logfile 2>&1" > logfile >2&1

mark
the future will be a lot like now, only later
Hai Nguyen_1
Honored Contributor

Re: exec command in script from another user

Jerome,

su is the way to go.

su - user_id -c "command string with or without options"

man su for more information.

Hai