I m writing a simple python script to analyze the logs in real time. I don't know how to move the cursor to the end of the freshly written data in log files in 30 seconds.
I have read all the related links Python parsing log file to extract events in real time and this http://www.dabeaz.com/generators/follow.py I have also read about seek() function but I'm not getting how do I use it.
But none of them answer to my questions. I don't even know to do I start.
import time
import csv
import parser as p
def follow(thefile):
logfile = open("access.log","r")
thefile.seek(0,2)
loglines = thefile.read()
p.process1(loglines) # user defined function 1
p.process2(loglines) # user defined function 2
print "Lines Converted: "
for line in loglines:
print line,
if __name__ == '__main__':
while(True):
follow()
time.sleep(30)
After reading the updated data in log files written in 30 seconds, the function should call the user defined function to perform the other operation on the new log data.