I'd like to create a ruby script which acquires variable from user with "gets" and then passes this variable to a Linux shell password prompt.
An example would be:
sudo apt-get update
Which would produce:
[sudo] password for username:
And there Ruby script should pop in that variable so the update could be executed.
Any help will be appreciated!
For security reasons, sudo doesn't accept passwords on standard input by default. You should configure your sudoers file with a
NOPASSWD:
tag for the commands you want to execute without prompting, and invoke sudo with the-n
flag to ensure that your script doesn't get hung up waiting for input.If you insist on passing in passwords, see if your sudo supports the
-S
flag, which (on my system) says: