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

Buffer size for ssh session in paramiko-expect #29

Open elmb opened 7 years ago

elmb commented 7 years ago

I am using paramiko-expect to send commands to a server. It is working as expected except when there is pagination options in the returned prompt. In that case, the output text is missing the first character in the output of each new page command and sometimes hangs and doesn't see the matching regular expression which was displayed. Putting buffer_size=1 is the only thing that fixes it for me 100%. Even putting the buffer size to 32 shows the same issues again.

That solution is too slow though, is there anything else I can do?

interact = SSHClientInteraction(ssh, timeout=300, display=True, buffer_size=1)  
output = ''
command = "file search activelog /platform/log/certm.log INFO"
not_done = True
interact.send(command)
while not_done:
    interact_index = interact.expect(['.*Press <enter> for 1 line, <space> for one page, or <q> to quit', '.*Search completed'])
    output += interact.current_output_clean
    if interact_index == 0:
        time.sleep(1)
        interact.send(' ')
    else:
        not_done = False
print(output)

ssh.close()
fruch commented 6 years ago

I think trying to work with a UI via paramiko-expect, might be a bit tricky, cause of the way those type of application are working.

I would better find a way to not paginate, and read all the data, and work with it.