I\'m using Paramiko to tail -f
a file on a remote server.
Previously, we were running this via ssh -t
, but that proved flaky, and the
You can use get_pty as described in https://stackoverflow.com/a/38883662/565212.
E.g. scenario - When to call client/channel.close():
Step1: Execute a remote command that writes to the log file.
Step2: Spawn a thread that executes the tail command and blocks in the readline loop
Step3: In main thread, when the command returns, you know there will be no more logs, kill the tail thread.
I just hit this issue and wasn't in a position to issue a pkill to close the process at the end.
A better solution is to change the command you are running to:
tail -f /path/to/file & { read ; kill %1; }
This will let you run your tail command for as long as you need. As soon as you send a newline to the remote process the kill %1 will execute and stop the tail command you backgrounded. (for reference: %1 is a jobspec and used to describe the first process that has been backgrounded in your session, ie the tail command)