1.

Solve : su command: enter password automatically????

Answer»

I am currently doing a script that will automatically bounce or start or STOP or simply monitor the webserver. The script's functionality is now working.

We now need to add another fuctionality that will switch users (using the su command) from the current USER to an ID with root access. Here's what i am thinking...
Steps:
1. any ID that does not have a root access (say user-X) will switch user to an ID with root access (say user-R), user-R's password is hardcoded inside the script.

2. inside the script, user-R will then EXECUTE a sudo su - to be ABLE to have root access.

The problem is when the script executes the su, it prompts for the password and needs to be entered manually.

IS THERE A WAY THAT WE CAN AUTOMATICALLY INPUT THE PASSWORD?

thanks for the help
my question... my answers.

I am logged in as USER_X and wanted to execute the command "whoami" as USER_R.

here's the resolution.

su USER_R -c "whoami"

this will execute the command as USER_R. you can also run a script using the same syntax

su USER_R -c "scriptname"



Discussion

No Comment Found