0

ホーム ディレクトリ (/home/name) の下に pyinotify を使用してスクリプトを配置し、実行します。スクリプトにホーム ディレクトリ (/home/name) またはルート (/) や /home/ などのホーム ディレクトリを含むディレクトリを監視させることはできません。/var、/boot、/home/name/Documents など、他のディレクトリはすべて問題ありません。

きれいな方法で説明しましょう。

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()
4

1 に答える 1

1

ホームディレクトリに時計を指定する必要があると思います。

wm.add_watch('/home', pyinotify.ALL_EVENTS, rec=True)
于 2014-01-09T01:38:05.917 に答える