Python paramiko script, problems reading output during exec_command()

前端 未结 4 1910
南方客
南方客 2021-01-02 04:03

Background: I am using python and paramiko to automate the process I go through everytime I have to hand in a program for a class. We use a command called

4条回答
  •  再見小時候
    2021-01-02 04:41

    To workaround this and get the output of Ifconfig, you may wanna try to use the option get_pty=True

    e.g:

    import paramiko
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    
    def MonitorProcess():
        ssh.connect('10.2.0.230', username='ibmsys1', password='passw0rd', timeout=5)
        stdin, stdout, stderr = ssh.exec_command('/sbin/ifconfig', timeout=3, get_pty=True)
        #stdin, stdout, stderr = ssh.exec_command('/sbin/ifconfig') -> simple exec ex.
        print stdout.read()
    
    MonitorProcess()
    

提交回复
热议问题