Py模拟远程tail

本地

俊杰蔡 <[email protected]>
reply-to        [email protected]
to      [email protected]
date    Fri, Jun 13, 2008 at 15:23
subject [CPyUG:54525] 远程tail -f功能的问题

   1     file = open("access_log.2008061311","r")
   2     while 1:
   3         where = file.tell()
   4         content = file.readlines()
   5         if not content:
   6             time.sleep(1)
   7             file.seek(where)
   8         else:
   9             print content

远程~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 [2008-06-15 06:43:49]

MiscItems/2008-06-15 (last edited 2009-12-25 07:09:50 by localhost)

Loading