【发布时间】:2016-11-06 02:59:56
【问题描述】:
我想使用 python paramiko 调用远程机器上的应用程序;此应用程序会等待您输入特定字符串,然后成功。如何通过 SSH 连接向它发送请求的字符串?
应用调用如下:
./app --init
This option will delete the database and recreate all files.
OLD DATA (IF ANY) WILL BE LOST!
This option must be used just on one of your servers.
Running it on any one of the servers will delete the other server's data, too.
If you are sure, type the following sentence and press ENTER:
I KNOW THAT THIS OPTION DESTROYS EVERYTHING; DO IT ANYWAY.
然后我应该输入I KNOW THAT THIS OPTION DESTROYS EVERYTHING; DO IT ANYWAY. 并按ENTER 继续。
我有这个代码可以连接到远程主机:
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(ip, username=usrname, password=passwd, compress=True)
我试过self.sshlink.exec_command('cd app_addr;./app --init');它什么也没做。
【问题讨论】:
-
如果您询问如何以编程方式执行此操作,那么如果重定向标准输入不起作用,您可以使用Expect。您需要查看 Expect 是否可作为您的操作系统的软件包使用,无论是什么。
-
paramiko 怎么用,有什么不好用的?
-
@SergeBallesta,请检查我的编辑!
标签: python ssh prompt paramiko