cancel
Showing results for 
Search instead for 
Did you mean: 

Scripting Question

SOLVED
Go to solution
TheJuiceman
Super Advisor

Scripting Question

How can I execute a script as another user while logged in as root? I need to be able to do this without the system asking me for that user's password. Any help is appreciated.
4 REPLIES
Brian Crabtree
Honored Contributor
Solution

Re: Scripting Question

su username -c "script"

While logged in as root, this will not ask for a password.

Brian
Ricardo Bassoi
Regular Advisor

Re: Scripting Question


Hi,

If you are login with the user root then:

su - $USER -c $COMMAND

An example is:

su - user -c "ls -al"

Regards,

Bassoi
If you never try, never will work
Franky Leeuwerck_1
Regular Advisor

Re: Scripting Question

Hello,

You can do this even as a cron job by adding an entry in the crontab, example :


01 4 * * * su - myUser /pathToScript/script

Be sure that your script invokes the necessary environment variables.

Franky
vasundhara
Frequent Advisor

Re: Scripting Question

Hi,

This can be achieved by using sticky bit concept also. I am also not perfect with sticky bit concept, but I know u can use this to set effective user id / real user id.

Regards
VJ.