我在home dir (/home/name)下放置了一个使用pyinotify的脚本,并运行它。虽然我不能让脚本监视我的home dir ( / home / name)或包含我的home dir的dir,比如root (/)和/home/。所有其他的dirs都可以,如/var、/boot、/home/name/Document。
让我用一种清晰的方式来描述它:
dirs that are NOT OK:
/
/home
/home/name (script is here)
All other dirs are OK, e.g.
/bin
/var
/home/name/Documents脚本:
import pyinotify
class MyEventHandler(pyinotify.ProcessEvent):
def process_IN_ACCESS(self, event):
print "ACCESS event:", event.pathname
def process_IN_ATTRIB(self, event):
print "ATTRIB event:", event.pathname
def process_IN_CLOSE_NOWRITE(self, event):
print "CLOSE_NOWRITE event:", event.pathname
def process_IN_CLOSE_WRITE(self, event):
print "CLOSE_WRITE event:", event.pathname
def process_IN_CREATE(self, event):
print "CREATE event:", event.pathname
def process_IN_DELETE(self, event):
print "DELETE event:", event.pathname
def process_IN_MODIFY(self, event):
print "MODIFY event:", event.pathname
def process_IN_OPEN(self, event):
print "OPEN event:", event.pathname
def main():
# watch manager
wm = pyinotify.WatchManager()
wm.add_watch('/var/log', pyinotify.ALL_EVENTS, rec=True)
# event handler
eh = MyEventHandler()
# notifier
notifier = pyinotify.Notifier(wm, eh)
notifier.loop()
if __name__ == '__main__':
main()发布于 2014-01-09 01:38:05
认为你需要指定一个手表给你的家庭显示器。
wm.add_watch('/home', pyinotify.ALL_EVENTS, rec=True)https://stackoverflow.com/questions/20989890
复制相似问题