parsing - Python script to extract new data from file since it was last read -



parsing - Python script to extract new data from file since it was last read -

i working on python script following:-

i read log file every 10 mins , on each read, extract added info file since lastly read (preferably without having read entire log file each time). example:-

at 09:00 read log file , content is:-

1. 2011-07-04 11:15:04,507 processing request 17897931 status 7 13 2. 2011-07-04 11:15:04,508 processing request 17897931 status 13 17 3. 2011-07-04 11:15:04,508 processing request d0fcb681 status 7 13 4. 2011-07-04 11:15:04,509 processing request d0fcb681 status 13 17 5. 2011-07-04 11:15:04,509 processing request 178819a1 status 7 13

at 09:10 read log file 1 time again , content is:-

1. 2011-07-04 11:15:04,507 processing request 17897931 status 7 13 2. 2011-07-04 11:15:04,508 processing request 17897931 status 13 17 3. 2011-07-04 11:15:04,508 processing request d0fcb681 status 7 13 4. 2011-07-04 11:15:04,509 processing request d0fcb681 status 13 17 5. 2011-07-04 11:15:04,509 processing request 178819a1 status 7 13 6. 2011-07-04 11:15:04,510 processing request 178819a1 status 13 17 7. 2011-07-04 11:15:04,510 processing request 17161df1 status 7 13 8. 2011-07-04 11:15:04,511 processing request 17161df1 status 13 17 9. 2011-07-04 11:15:04,511 processing request 182013e1 status 7 9

how can script extract new lines (lines 6. 9.)?

i have shell script doing task using file's inode. looking solution based on python.

my plan execute script via crontab.

do guys have thought how can done?

check size of file wait until size changes open file, seek previous size read

example:

import os, time size = os.stat(file).st_size time.sleep(600) fh = open(file) fh.seek(size) newdata = fh.read()

this illustration will, time time, read partial line if process writing log @ same time. i'll leave solution exercise :)

python parsing extraction

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -