fgimian / paramiko-expect

A Python expect-like extension for the Paramiko SSH library which also supports tailing logs.
MIT License
204 stars 78 forks source link

Paramiko expect on windows 2019 vms is giving a lot of residue output #98

Open basu45 opened 3 months ago

basu45 commented 3 months ago

When expect function is used to extract data from windows 2019 machine we are getting a lot of garbage in output .

basu45 commented 3 months ago

@sriramkannan95 can u help on this issue

sriramkannan95 commented 3 months ago

Details please? Show the part of code that is giving the issue. What exactly are you trying to do and what did you get?

basu45 commented 3 months ago

@sriramkannan95 The code is ''' Import paramiko From paramiko-expect import SSHClientInteraction Client=paramiko.SSHClinet() Client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) Client.connect(hostname,user,password) Interact=SSHClientInteraction(Client,timeout=60,) Interact.expect(r'.[\$#>]\s+) Interact.send('who am i') Interact.expect(r'.[\$#>]\s+) ''' Ssh is done to 2019 windows vm Getting similar output as of https://stackoverflow.com/questions/61381631/read-buffer-data-continuously-running-on-remote-windows-command-prompt?noredirect=1&IQ=1

And also same output is repeated more than once

basu45 commented 3 months ago

Doesnot look like exepect issue Looks like issue with how paramiko interacts with 2019 ssh

fruch commented 3 months ago

The issue seems like Unicode escape sequences.

The code should be taking them out, if it works as expected

fruch commented 3 months ago

The issue seems like Unicode escape sequences.

The code should be taking them out, if it works as expected

Also see https://superuser.com/a/1785495/1256163

The best thing would be to make sure pty is for sure turned off, and the rest of the suggestion made there

basu45 commented 3 months ago

The issue seems like Unicode escape sequences. The code should be taking them out, if it works as expected

Also see https://superuser.com/a/1785495/1256163

The best thing would be to make sure pty is for sure turned off, and the rest of the suggestion made there

But how to turn off the pty. The SSHClientInteraction class init method itself calls invoke_shell() which inherently requests a pty

NOTE: THE ISSUE IS ONLY WITH 2019 WINDOWS VERSION

basu45 commented 3 months ago

Update:tested with bitvise ssh server in place of openssh server it appears to be working fine with it. But we cannot use bitvise ssh server as it's paid version for organization level.

basu45 commented 3 months ago

Hi any suggestions??

basu45 commented 2 months ago

Hello, Any updates??

amittendulkar commented 2 months ago

@fruch, @sriramkannan95,

I believe the ask here is for paramiko_expect to provide a mechanism to turn off the pty. Currently I see that it is internally calling client.invoke_shell() in the SSHClientInteraction constructor,

self.channel = client.invoke_shell(term=term, width=tty_width, height=tty_height)

I believe the client.invoke_shell() internally calls get_pty(). Is it possible to do something discussed on the below lines (have a flag in the constructor to get the channel.invoke_shell() called without calling get_pty())? https://stackoverflow.com/questions/58063024/can-i-call-channel-invoke-shell-without-calling-channel-get-pty-beforehand

This can be considered as an enhancement and not a bug as we want to support SSH server on the new OS type/version.