pyinotify 实时监控文件系统更改

Posted on Posted in 监控

pyinotify 实时监控文件系统更改

github

安装

pip install pyinotify

#或

# git clone https://github.com/seb-m/pyinotify.git
# cd pyinotify/
# ls
# python setup.py install

使用

# python -m pyinotify -v ./tmp # 可以监控到该目录的事件
[2017-04-14 10:13:47,186 pyinotify DEBUG] Start monitoring ['./tmp'], (press c^c to halt pyinotify)
[2017-04-14 10:13:47,189 pyinotify DEBUG] New <Watch wd=1 path=tmp mask=4095 proc_fun=None auto_add=None exclude_filter=<function <lambda> at 0x76661bf0> dir=True >
[2017-04-14 10:14:05,525 pyinotify DEBUG] Event queue size: 48
[2017-04-14 10:14:05,528 pyinotify DEBUG] <_RawEvent cookie=0 mask=0x40000020 name='' wd=1 >
[2017-04-14 10:14:05,529 pyinotify DEBUG] <_RawEvent cookie=0 mask=0x40000001 name='' wd=1 >
[2017-04-14 10:14:05,532 pyinotify DEBUG] <_RawEvent cookie=0 mask=0x40000010 name='' wd=1 >
<Event dir=True mask=0x40000020 maskname=IN_OPEN|IN_ISDIR name='' path=tmp pathname=/home/pi/tmp wd=1 >
<Event dir=True mask=0x40000001 maskname=IN_ACCESS|IN_ISDIR name='' path=tmp pathname=/home/pi/tmp wd=1 >
<Event dir=True mask=0x40000010 maskname=IN_CLOSE_NOWRITE|IN_ISDIR name='' path=tmp pathname=/home/pi/tmp wd=1 >
[2017-04-14 10:14:36,916 pyinotify DEBUG] Event queue size: 64
[2017-04-14 10:14:36,918 pyinotify DEBUG] <_RawEvent cookie=0 mask=0x40000100 name=1 wd=1 >
[2017-04-14 10:14:36,919 pyinotify DEBUG] <_RawEvent cookie=0 mask=0x40000100 name=2 wd=1 >
<Event dir=True mask=0x40000100 maskname=IN_CREATE|IN_ISDIR name=1 path=tmp pathname=/home/pi/tmp/1 wd=1 >
<Event dir=True mask=0x40000100 maskname=IN_CREATE|IN_ISDIR name=2 path=tmp pathname=/home/pi/tmp/2 wd=1 >
[2017-04-14 10:14:36,925 pyinotify DEBUG] Event queue size: 32
[2017-04-14 10:14:36,927 pyinotify DEBUG] <_RawEvent cookie=0 mask=0x40000100 name=3 wd=1 >
<Event dir=True mask=0x40000100 maskname=IN_CREATE|IN_ISDIR name=3 path=tmp pathname=/home/pi/tmp/3 wd=1 >

Leave a Reply

Your email address will not be published. Required fields are marked *

eighteen − four =