1

I have created a fabfile with multiple hosts.

I am automating my experiment. When i run the command "sudo adduser --ingroup hadoop hduser" it will ask for the following.

  1. New unix password
  2. confirm Password.
  3. Full Name
  4. Room,Ph,etc
  5. is this information Correct? Y/N

I would like to pass all this information as part of script without prompting user. How can i do this ?

Thanks

Navaz

navaz
  • 125
  • 1
  • 2
  • 15
  • 1
    I think this is a [duplicate](http://stackoverflow.com/questions/3190955/how-to-create-a-user-in-linux-using-python) or anyway, it'll help you – fernandezr Oct 28 '14 at 19:29

2 Answers2

1

Why didn't you just use pipes?

For example, for an automated auto accept, just use yes, that just outputs a neverending stream of y.

yes | rm *.txt

in your case:

local('echo 'your_super_password\n' | sudo adduser --ingroup hadoop hduser')
Ekin Ertaç
  • 325
  • 3
  • 13
1

Another option is to use fexpect, an extension of fabric that enables you to respond to prompts:

from ilogue.fexpect import expect, expecting, run 

prompts = []
prompts += expect('What is your full name?','John Doe')
prompts += expect('is this information Correct? Y/N','Y')

with expecting(prompts):
    sudo('adduser --ingroup hadoop hduser')
Jasper van den Bosch
  • 3,169
  • 4
  • 32
  • 55