Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Fabric: How to handle arbitrary remote shell prompt for input?

This is related to this question here, but with a slight twist: instead of just passing 'yes' or 'no', I need Fabric to pass an arbitrary string to the remote shell.

For instance, if the remote shell prompts for 'what is your name?' then I need to feed it 'first,last'.

Clarification: I know I said arbitrary input, but I was really trying to use it for the SSH key passwd prompt when I try to do a git pull.

Update #1: Got a response from Jeff Forcier @bitprophet

  • that’s like the #1 wart right now :( Either tunnelling to send a key agent out-of-band, or remote prompting, is needed.

  • I meant adding support for those things in Fabric, is what we need to do to get network-borne git ops working

  • Adding an easy way to kick off an OOB ssh agent-friendly tunnel is going to be easier/faster, most likely. Soon probably

like image 281
Jay Avatar asked Apr 16 '10 02:04

Jay


1 Answers

I have proposed an API for this feature in fabric on the mailinglist, and ended up writing something myself:

from fexpect import expect, expecting, run 

prompts = []
prompts += expect('What is your name?','John')
prompts += expect('Where do you live?','New York')

with expecting(prompts):
    run('command')

See my blogpost on expecting prompts in fabric with fexpect

like image 92
Jasper van den Bosch Avatar answered Sep 21 '22 19:09

Jasper van den Bosch