⇤ ← Revision 1 as of 2008-06-15 06:43:49
Size: 1635
Comment:
|
Size: 1650
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 38: | Line 38: |
== 远程 == | == 远程~paramiko模块 == |
Py模拟远程tail
本地
俊杰蔡 <[email protected]> reply-to [email protected] to [email protected] date Fri, Jun 13, 2008 at 15:23 subject [CPyUG:54525] 远程tail -f功能的问题
- 如何用python来实现远程tail -f的功能? 各位有什么好的思路么? 本地模拟tail -f功能可以这样:
- 我初步想到的一个办法是把上面的代码放到B机器上运行,A机器起个监听程序,接收B机器返回的内容。但这样不够pythonic。有没有更加好的方法呢?
远程~paramiko模块
paramiko模块基本可以满足要求
1 import paramiko as ssh
2 client=ssh.SSHClient()
3 client.load_system_host_keys()
4 client.connect(host,22,username,"",None,None)
5 stdin, stdout, tderr = self.client.exec_command("tail -f log")
6 line = stdout.readline()
7 while line:
8 #myTime = strftime('%H:%M:%S', localtime())
9 print("[%s] %s" % (self.host,line))
10 line = stdout.readline()
反馈
创建 by -- ZoomQuiet [DateTime(2008-06-15T06:43:49Z)]