【问题标题】:Paramiko SSH output not capturing command outputParamiko SSH 输出未捕获命令输出
【发布时间】:2012-06-29 08:14:25
【问题描述】:

我有一个小脚本可以在设备中执行命令。我没有在标准输出中获取命令的输出,而是在登录设备后在命令提示符之前打印所有这些输出。

import paramiko, 
client = paramiko.SSHClient()
client.load_system_host_keys()
client.connect('10.88.124.88', username='admin',password='testing',timeout=15.0)
print "Connected...\n"
print "Executing show version...\n"
stdin, stdout, stderr = client.exec_command("show version")
print "AFTER Executing show version...\n"
stdin.channel.shutdown_write()
print "BEFORE Reading output...\n"
output = stdout.read()
print "AFTER Reading output...\n"
print "OUTPUT:: '", output, "'"
print "Execting quit...\n"
stdin, stdout, stderr = client.exec_command("quit\n")

我从脚本中得到的输出如下所示。我期待在输出中输出“显示版本”。不知道我在哪里失踪。设备的响应有点慢。

[root@dev-s2-3m7-aio-139-44 ~]# ./ssh-bana.py
Connected...
...
OUTPUT:: ' Command Line Interface is starting up, please wait ...
verifying connection to main (admin@192.168.0.2)... success
verifying connection to secondary (admin@192.168.1.2)... success

   Welcome to the TelePresence Command Line Interface (version 1.1)

Last login: Wed Jun 27 14:45:21 CDT 2012 from 10.88.139.44

admin: '
Execting quit...

【问题讨论】:

    标签: ssh paramiko


    【解决方案1】:

    在执行 show version 命令后立即添加:

        print "".join(stdout.readlines()) 
    

    【讨论】:

      猜你喜欢
      • 2017-02-26
      • 1970-01-01
      • 2012-02-18
      • 1970-01-01
      • 2018-01-28
      • 1970-01-01
      • 1970-01-01
      • 2013-01-16
      • 1970-01-01
      相关资源
      最近更新 更多