daily pastebin goal
60%
SHARE
TWEET

Untitled

a guest Oct 21st, 2018 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import os
  2. import time
  3.  
  4. class monitor(object):
  5.     def __init__(self, name):
  6.         self.file_name = os.path.abspath(name)
  7.         self.file      = open(self.file_name)
  8.         self.bytes     = os.stat(self.file_name).st_size
  9.         self.mtime     = os.path.getmtime(self.file_name)
  10.    
  11.     def check(self):
  12.         mtime = os.path.getmtime(self.file_name)
  13.         if mtime <= self.mtime:
  14.                     return
  15.                 self.file.seek(self.bytes)
  16.         data = self.file.read()
  17.         self.mtime = mtime
  18.         self.bytes = self.file.tell()
  19.                 if data:
  20.                     return data.splitlines()
  21.  
  22. x = monitor("/users/cam/downloads/server.log")
  23. while 1:
  24.     z = x.check()
  25.     if z!=None:
  26.         print z
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top