I want to run a tail -f logfile
command on a remote machine using python's paramiko module. I've been attempting it so far in the following fashion:
interface = paramiko.SSHClient()
#snip the connection setup portion
stdin, stdout, stderr = interface.exec_command("tail -f logfile")
#snip into threaded loop
print stdout.readline()
I'd like the command to run as long as necessary, but I have 2 problems:
- How do I stop this cleanly? I thought of making a Channel and then using the
shutdown()
command on the channel when I'm through with it- but that seems messy. Is it possible to do something like sentCtrl-C
to the channel's stdin? readline()
blocks, and I could avoid threads if I had a non-blocking method of getting output- any thoughts?