我试图通过自动化的Fabric如下:是否可以使用结构将命令传递到交互式shell?
- SSH到远程主机。
- 执行一个python脚本(Django management command
dbshell
)。 - 通过已知值提示脚本生成。
如果我手动做到这一点,想是这样的:
$ 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....