我想使用python的paramiko模塊在遠程計算機上運行tail -f logfile
命令。我一直到目前爲止,它試圖以下列方式:python paramiko模塊中的長時間運行的ssh命令(以及如何結束它們)
interface = paramiko.SSHClient()
#snip the connection setup portion
stdin, stdout, stderr = interface.exec_command("tail -f logfile")
#snip into threaded loop
print stdout.readline()
我想在必要時運行長的命令,但我有2個問題:
- 如何停止該乾淨?我想要製作一個頻道,然後在頻道上使用
shutdown()
命令,但這似乎很麻煩。是否可以做一些事情,如發送Ctrl-C
到頻道的stdin? readline()
塊,我可以避免線程,如果我有一個非阻塞方法獲取輸出 - 任何想法?
討厭打破壞消息,但SSHClient()已在內部使用線程。 – joeforker 2009-05-12 20:20:35