0

Possible Duplicate:
automate sudo su - user command

when the sudo su - user command gets executed inj script ,it asks for a password. i want a solution in which script automaticaaly reads password from somewhere. i dont have permission to edit sudoers file.i have the permission to store password in a file.the script should read password from that file . also expect is not installed and i do not have permission to install it on machine from where the script would be run

sam
  • 101

1 Answers1

1

You can use command

 echo "your_password" | sudo -S <rest of your parameters for sudo>

(Of course without < and >)

Please note that you should protect your script from read access from unauthorized users. If you want to read password from separate file, you can use

 cat /etc/sudo_password_file | sudo -S <rest of your parameters for sudo>

(Or whatever is the name of password file, containing password and single line break.)

From sudo man page:

   -S          The -S (stdin) option causes sudo to read the password from
               the standard input instead of the terminal device.  The
               password must be followed by a newline character.
Olli
  • 7,739