Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

share|improve this question

marked as duplicate by DMA57361 Feb 9 '11 at 12:51

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
Please do not duplicate your own questions; if you need to you can use the edit function at the bottom of the question you have already asked to add further details. –  DMA57361 Feb 9 '11 at 12:52

1 Answer 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.
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.