【发布时间】:2011-10-12 02:40:54
【问题描述】:
我正在使用 Paramiko 来tail -f 远程服务器上的文件。
以前,我们通过ssh -t 运行此程序,但事实证明这很不稳定,-t 导致我们的远程调度系统出现问题。
我的问题是当脚本捕捉到信号时如何杀死尾巴?
我的脚本(基于Long-running ssh commands in python paramiko module (and how to end them))
#!/usr/bin/env python2
import paramiko
import select
client = paramiko.SSHClient()
client.load_system_host_keys()
client.connect('someserver', username='victorhooi', password='blahblah')
transport = client.get_transport()
channel = transport.open_session()
channel.exec_command("tail -f /home/victorhooi/macbeth.txt")
while True:
try:
rl, wl, xl = select.select([channel],[],[],0.0)
if len(rl) > 0:
# Must be stdout
print channel.recv(1024)
except KeyboardInterrupt:
print("Caught control-C")
client.close()
channel.close()
exit(0)
脚本成功捕获我的 Ctrl-C 并结束。但是,它使tail -f 进程在远程系统上运行。
client.close() 和 channel.close() 似乎都不会终止它。
我可以在 except 块中发出什么命令来杀死它?
远程服务器正在运行 Solaris 10。
【问题讨论】:
标签: python ssh solaris signals paramiko