Paramiko: read from standard output of remotely executed command

后端 未结 3 1511
孤城傲影
孤城傲影 2020-12-03 18:28

so I was working with paramiko for some basic SSH testing and I\'m not getting any output into stdout. Heres my code.

import paramiko
client=paramiko.SSHCli         


        
3条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-03 18:33

    # Program to print the output in console/interpreter/shell in runtime without using stdout.
    
     import paramiko
     import xlrd
     import time
    
     ssh = paramiko.SSHClient()
     ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    
     loc = ('/Users/harshgow/Documents/PYTHON_WORK/labcred.xlsx')
     wo = xlrd.open_workbook(loc)
     sheet = wo.sheet_by_index(0)
     Host = sheet.cell_value(0, 1)
     Port = int(sheet.cell_value(3, 1))
     User = sheet.cell_value(1, 1)
     Pass = sheet.cell_value(2, 1)
    
     def details(Host, Port, User, Pass):
           time.sleep(2)
    
           ssh.connect(Host, Port, User, Pass)
           print('connected to ip ', Host)
    
           stdin = ssh.exec_command("")
           remote_conn = ssh.invoke_shell()
           print("Interactive SSH session established")
    
           output = remote_conn.recv(1000)
           remote_conn.send("\n")
           remote_conn.send("xstatus Cameras\n")
    
           time.sleep(5)
           output = remote_conn.recv(10000)
           print(output)
    
     details(Host, Port, User, Pass)
    
    

提交回复
热议问题