1827318 Members
6673 Online
109961 Solutions
New Discussion

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.
5 REPLIES 5
malay boy
Trusted Contributor
Solution

Re: Scripting question

well you can used su -c .

Example : let say the user script call find_file.sh

so :

su mb -c "/home/find_file.sh"

hope this help.
There are three person in my team-Me ,myself and I.
Michael Tully
Honored Contributor

Re: Scripting question

Well if your root, you can use any account. Typically you use:

su - account -c "command"

Using this example as root, you won't need a password.
Anyone for a Mutiny ?
Con O'Kelly
Honored Contributor

Re: Scripting question

Hi

I guess the following should work:
# su - -c "/fullpath/scriptname"

Cheers
Con
twang
Honored Contributor

Re: Scripting question

If you login as root and use "su", system will not ask for a password, simple issue the following to test and see:
# su - -c date

Kevin O'Donovan
Regular Advisor

Re: Scripting question

I know this is already sorted, but just another possibility to throw in there...

If its a particular user, you could set the owner of the file to the user you want to run it as, and then set the setuid bit, so it will run as the user its owned by. Do this with chmod +s .

Note this can pose a bit of a security risk but its an alternative to the su -c everyone else has!

Kev.