実現したいこと
NASのあるディレクトリにファイルが追加された場合に、それをマウントしているコンピュータ(linux mint 21)でそのイベントをキャッチしたいと思っています。
pythonのwatchdogとシェルのinotifywaitを試してみたのですがうまくいきません。
発生している問題・エラーメッセージ
linux mint 21にNASのあるディレクトリをマウントしています。
マウントサイトが「/mnt/nas/share」とすると、そのディレクトリにコンピュータ側から何らかの修正・ファイル追加をおこなうとpythonのwatchdogでもinotifywaitでもイベントをキャッチできるのですが、NASのディレクトリにNAS上でファイルを追加した場合には「/mnt/nas/share」の中身が変更されたにもかかわらず、そのイベントをコンピュータ側からはキャッチできません。
該当のソースコード
python
from watchdog.events import FileSystemEventHandler from watchdog.observers import Observer import time class ChangeHandler(FileSystemEventHandler): def on_any_event(self, event): print('[全て]',event) def on_created(self, event): print('[作成]',event) def on_modified(self, event): print('[変更]', event) def on_moved(self, event): print('[移動]',event) observer = Observer()observer.schedule(ChangeHandler(), '/mnt/nas/share', recursive=True)observer.start() while True: time.sleep(5)
shell
inotifywait -e create,delete,modify,move -mr /mnt/nas/share
補足情報
watchdogやinotifywaitで不可能であれば、他にいい方法はないでしょうか?

0 コメント