LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Question about using sudo su (https://www.linuxquestions.org/questions/linux-newbie-8/question-about-using-sudo-su-653610/)

bgrantham 07-04-2008 01:17 PM

Question about using sudo su
 
Hi,

I have a need to run a script as another user, but the current process takes three commands to do.

sudo su - user
cd directory/
./script.sh

The account is set up such that doing the 'sudo su - user' requires no password.

I am trying to get this into a single command or shell script which I can run to accomplish the same thing. I tried using the -c flag of su, however I am required to enter a password with this flag. I can't enter a password, since I haven't been given a password.

Any help would be appreciated.

Thanks,
Beau

stress_junkie 07-04-2008 02:55 PM

Disregard this.

Tinkster 07-04-2008 03:30 PM

Can you not put
Code:

su - user -c "cd /path/to/directory && ./script"
into e.g. runme.sh, modify sudoers to allow you to run
runme.sh w/o a password and then do sudo runme.sh?



Cheers,
Tink

Mr. C. 07-04-2008 03:32 PM

sudo su is superfluous. Use either sudo or su, you don't need both together.

If you want your script run as a different user, use any of these:

sudo -u user directory/myscript.sh
sudo -u user sh -c 'cd directory; ./myscript.sh'

bgrantham 07-04-2008 09:28 PM

Quote:

Originally Posted by Tinkster (Post 3204277)
Can you not put
Code:

su - user -c "cd /path/to/directory && ./script"
into e.g. runme.sh, modify sudoers to allow you to run
runme.sh w/o a password and then do sudo runme.sh?



Cheers,
Tink

Thanks for the suggestion Tink, I tried this too. I think I am going to have to get the server admin to change the sudoers file, as you suggested in order to accomplish this.

Thanks again,
Beau

Mr. C. 07-04-2008 09:41 PM

The su program does not use sudoers; only sudo users sudoers.


All times are GMT -5. The time now is 05:10 PM.