Question

I am trying to make a small module which opens an ssh connection and allows to send commands over ssh and return the output of the command. Hereby, there should only be one ssh connection (so that multiple commands do not cause auto-blocks). I am aware of paramiko, but I cannot use it as I have to use python3.2 because of other constraints.

The module I wrote is here: http://kbicker.web.cern.ch/kbicker/ssh.py

In principle, it works. However, when using cat to read a text file, the program hangs. I determined that this is because reading a new line from the pty hangs. I assume, there is some kind of buffer problem, but I have no idea how to solve it.

I would also be grateful for any other advice on my code.

Thank you in advance for your help!

Was it helpful?

Solution

Solved, or at least worked around it:

By using a thread with the ssh -M option, I could have one Master ssh connection open and have commands open their own ssh subprocess, which connects through the master connection, thereby alleviating the need to open more than one connection.

OTHER TIPS

Try pexpect. I ran into a similar problem and it solved it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top