Fabric-如何在远程计算机上使用交互式外壳? [英] Fabric - how to use an interactive shell on remote computer?
问题描述
我正在尝试使用Fabric在远程计算机上运行命令.
I am trying to use Fabric to run commands on a remote machine.
这可以正常工作,直到远程计算机上的命令是交互式的为止.在这种情况下,Fabric返回了交互式外壳程序,但是当我尝试发送一个可以远程执行所有操作的命令时,迫使我键入所需的信息,所以我可以使该过程自动化.
This works fine, until the command on the remote machine is interactive. In that case, Fabric return the interactive shell, but force me to type the info needed, while I am trying to send a command that does everything in remote, so I can automate the procedure.
示例:
from fabric.api import *
env.hosts=['myhost.mydomain']
env.user='root'
run(test1/myapp; exectask; exit)
我在使用交互式外壳程序的远程计算机上运行cli应用程序,因此它正在等待我键入命令(exectask);然后一旦完成,要退出,我会调用exit命令.
I run a cli application on a remote machine, that uses interactive shell, so it is waiting for me to type the command (exectask); then once done, to exit, I call the exit command.
现在发生的是,应用程序启动,Fabric向我显示了交互式UI,我仍然需要键入exectask,然后退出.
What happens now is that the app launch, Fabric show me the interactive UI and I still need to type exectask and after, exit.
我如何告诉Fabric运行该应用程序,然后将命令传递给交互式shell,然后退出以退出?
How can I tell fabric to run that app, then pass the command to the interactive shell and then the exit to quit?
我看到Fabric具有提示功能,但这是要求用户输入数据,而我只是想传递命令并返回结果.
I see that Fabric has the prompt feature, but that's to ask the user to input data, while I want to just pass the commands and get the result back.
推荐答案
您可能想研究 pexpect
,其纯Python模块的工作方式类似于 expect
.本质上,它允许您的程序生成外部程序或进程,然后像对其进行交互一样对其进行控制.您可以按照程序应该看到的内容(因此而命名)进行编程,然后执行什么操作.
You might want to look into pexpect
, a pure-Python module that works like expect
. Essentially, it allows your program to spawn an external program or process, then control it just like a human was interacting with it. You program in what the program should expect to see (hence the name), then what action(s) to take.
这篇关于Fabric-如何在远程计算机上使用交互式外壳?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!