2016-01-12 40 views
1

我试图通过自动化的Fabric如下:是否可以使用结构将命令传递到交互式shell?

  1. SSH到远程主机。
  2. 执行一个python脚本(Django management command dbshell)。
  3. 通过已知值提示脚本生成。

如果我手动做到这一点,想是这样的:

$ 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 

=========

我目前的解决方案看起来是这样的:

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.... 

回答

0

您可以使用Pexpect它运行系统并检查输出,如果输出匹配给定模式Pe xpect可以作为人类打字的响应。

1

通过Twitter回复了肖恩在此,而是要看看这里的第一件事就是http://docs.fabfile.org/en/1.10/usage/env.html#prompts - 并不完美,但在某些情况下:)

即将推出的V2具有更坚实的实现在这个功能就足够了管道,而且理想情况下,它也有更多像pexpect一样的API的空间(意思是更系列化的东西)。

相关问题