paramiko_expect互动无法发送命令

时间:2019-10-04 19:54:48

标签: python paramiko

我正在尝试编写一个Python脚本,该脚本通过SSH登录到Cisco CallManager系统并发出命令,在终端上回显所有输出并将其记录到文件中。一切看起来都很好。登录正常,我可以看到终端回显了输出,并将其记录到文件中,但是由于某种原因未输入命令。

关于此,我看了很多不同的文章,确实看起来我的代码应该可以工作,但只是没有输入命令。

callManager = "1.1.1.1"
username = "admin"
password = "pword"

ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(callManager, username=username, password=password)
interact = SSHClientInteraction(ssh, timeout=180, display=True)
interact.expect("admin:")
interact.send("show status")
output = interact.current_output_clean
ssh.close()
ip_file_name = callManager.replace(".","_")
output_file = "{}.txt".format(ip_file_name)
with open(output_file, "w") as out:
    out.write(output)

脚本完整无误。它甚至写入文件。我可以看到它进入“ admin:”提示符的位置,但随后就退出了。它不输入命令。

任何帮助将不胜感激。

0 个答案:

没有答案