Question

I would like to automate the response for some question prompted by some programs, like mysql prompting for a password, or apt asking for a 'yes' or ... when I want to rebuild my haystack index with a ./manage.py rebuild_index.

For MySQL, I can use the --password= switch, and I'm sure that apt has a 'quiet' like option. But how can I pass the response to other programs ?

Was it helpful?

Solution

Why can'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


(source: wikimedia.org)

OTHER TIPS

If you are looking for a user to confirm an operation, use the confrim method.

if fabric.contrib.console.confirm("You tests failed do you want to continue?"):
  #continue processing

Or if you are looking for a way to get input from the user, use the prompt method.

password = fabric.operations.prompt("What is your password?")

Those both methods are valid and works.

I choose the first one, because I didn't want to have any interaction with my deployment system.

So here is the solution I used:

% yes | ./manage.py rebuild_index

WARNING: This will irreparably remove EVERYTHING from your search index. Your choices after this are to restore from backups or rebuild via the rebuild_index command. Are you sure you wish to continue? [y/N] Removing all documents from your index because you said so. All documents removed. Indexing 27 Items.

The development version of Fabric (1.0a) now supports interaction with remote programs. http://docs.fabfile.org/1.0a/usage/interactivity.html

Late answer, but hope this would help peoples having similar problem.

Different point:

  1. Answer two or more different input to console.
  2. parallel mode Support.
  3. Any type of input yes/no/y/n included.

Problem

[hostxxx] out: Type 'c' if you want to use the Commercial Edition.
[hostxxx] out: Type 'o' if you want to use the Open Source Edition.
[hostxxx] out: Type '3' to view the GNU General Public License version 3.
[hostxxx] out: Type 'L' to view the Lesser GNU General Public License version 2.1.
[hostxxx] out: Type 'yes' to accept this license offer.
[hostxxx] out: Type 'no' to decline this license offer.

Solution:

Use printf instead of yes to add more flexibility, meanwhile this works like a charm on parallel mode.

@parallel
def demo_multi_input():
    run('printf "o\nyes\n"|./configure --prefix=/home/work/bin/qt')

Use this code:

run("echo yes|./manage.py rebuild_index")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top