表示打开通道作为响应

表示打开通道作为响应

本文介绍了Paramiko:收集输出的 ssh.exec_command 表示打开通道作为响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有带有 paramiko 和 ssh 的 python 脚本,如下

I have python script with paramiko and ssh somewhat as below

import paramiko

# setup ssh connection this works. no problem.
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
conn = ssh.connect(MACHINEIP, username=ROOTUSER, password=ROOTUSER_PASSWORD, port=22)

# This first ssh exec works perfect.
(sshin1, sshout1, ssherr1) = ssh.exec_command(cmd1)

# When I print the output of 2nd and 3rd ssh exec, I get output saying of channel open
(sshin2, sshout2, ssherr2) = ssh.exec_command(cmd2)
print sshout2
(sshin3, sshout3, ssherr3) = ssh.exec_command(cmd3)
print sshout3

多次使用 exec_command 收集输出时输出中的通道打开消息:

Channel open messages in output when exec_command is used more than once to collect output:

<paramiko.ChannelFile from <paramiko.Channel 2 (open) window=2097152
   -> <paramiko.Transport at 0x1d42bd0L (cipher aes128-ctr, 128 bits)
(active; 1 open channel(s))>>>

<paramiko.ChannelFile from <paramiko.Channel 6 (open) window=2097152
   -> <paramiko.Transport at 0x1d42bd0L (cipher aes128-ctr, 128 bits)
(active; 2 open channel(s))>>>

我怎样才能关闭这个开放的频道?或者有什么解决办法?我使用的是 python 2.7.

How can I close this open channel? Or any solution on this? I am using python 2.7.

推荐答案

应该用作 sshout.read() 而我只在打印时使用 sshout.

Should have used as sshout.read() and rather I used sshout only while printing.

这篇关于Paramiko:收集输出的 ssh.exec_command 表示打开通道作为响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 13:02
查看更多