Python pyinotify模块实现对文档的实时监控功能方法
0x01 安装pyinotify
>>> pip install pyinotify >>> import pyinotify
0x02 实现对文档的试试监控功能
这个功能类似与Ubuntu里的rail -f功能,在对目标文件进行修改时,脚本可以实时监控并将新的修改打印出来。
import pyinotify import time import os class ProcessTransientFile(pyinotify.ProcessEvent): def process_IN_MODIFY(self, event): line = file.readline() if line: print line, # already has newline filename = './test.txt' file = open(filename,'r') #Find the size of the file and move to the end st_results = os.stat(filename) st_size = st_results[6] file.seek(st_size) wm = pyinotify.WatchManager() notifier = pyinotify.Notifier(wm) wm.watch_transient_file(filename, pyinotify.IN_MODIFY, ProcessTransientFile) notifier.loop()
相关推荐
ROES 2020-10-24
lvxingzhe 2020-06-18
明天就流量监控 2020-06-10
aolia000 2020-05-29
流量监控lookman 2020-04-19
QAnyang 2020-03-14
流量监控lookman 2020-02-19
流量监控lookman 2020-01-06
流量监控lookman 2020-01-06
流量监控距离咯 2019-12-14
Noontec 2019-11-13
wpeng 2019-11-12
aweilark 2019-11-11
安防监控ezhf 2019-11-05
IA视频监控 2019-08-22
bktest 2019-10-21
zhangmiao 2015-07-22
bighandsky 2017-05-02