Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paramiko SSH ( Only tail commands not working) #1344

Open
Breme opened this issue Nov 30, 2018 · 1 comment
Open

Paramiko SSH ( Only tail commands not working) #1344

Breme opened this issue Nov 30, 2018 · 1 comment

Comments

@Breme
Copy link

Breme commented Nov 30, 2018

I tried to SSH to a linux server using paramiko and it worked like a charm. But When I use tail commands on the server I couldn't see the large streaming text on my console.import paramiko

import time
import subprocess

def ssh_to_server():
    try:
        hostname = "x.x.x.x"
        port = 22
        username = 'user'
        password = 'pass'
        
        ssh_connection = paramiko.SSHClient()
        ssh_connection.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        ssh_connection.connect(hostname, port, username, password)
        print("Connected to " + hostname)

        stdin, stdout, stderr = ssh_connection.exec_command(command ="xtail\n")

        # print("Executed")
      
        ssh_connection.close()
        print("--------->",stdout.readlines())
      
        

    except Exception as e:
        print("error#####",e)
        # print("STRERR##", stderr.readlines())    

if __name__ == '__main__':
    ssh_to_server()




The result I'm getting is

Connected to x.x.x.x
---------> []

But when I use other commands It works fine. Even streaming command like ping

@ploxiln
Copy link
Contributor

ploxiln commented Nov 30, 2018

You need to drain both stderr and stdout before closing the connection. This is not particularly easy and simple - you should probably use fabric.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants