1

I'm trying to automate the following via Fabric:

  1. SSH to a remote host.
  2. Execute a python script (the Django management command dbshell).
  3. Pass known values to prompts that the script generates.

If I were to do this manually, it would like something like:

$ ssh -i ~/.ssh/remote.pem [email protected] [email protected]$ python manage.py dbshell postgres=> Password For ubuntu: _____ # i'd like to pass known data to this prompt postgres=> # i'd like to pass known data to the prompt here, then exit 

=========

My current solution looks something like:

from fabric.api import run from fabric.context_managers import settings as fabric_settings with fabric_settings(host_string='10.10.10.158', user='ubuntu', key_filename='~/.ssh/remote.pem'): run('python manage.py dbshell') # i am now left wondering if fabric can do what i'm asking.... 

2 Answers 2

2

Replied to Sean via Twitter on this, but the first thing to check out here is http://docs.fabfile.org/en/1.10/usage/env.html#prompts - not perfect but may suffice in some situations :)

The upcoming v2 has a more solid implementation of this feature in the pipe, and that will ideally have room for a more pexpect-like API (meaning, something more serially oriented) as an option too.

Sign up to request clarification or add additional context in comments.

Comments

0

You can use Pexpect which runs the system and checks the output, if the output matches given pattern Pexpect can respond as a human typing.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.