I am trying to detect a file in a shared network directory using WatchDog 2.1.6 and Python 3.7.3 The o/s is Linux RHEL. Two machines m1 and m2 have processes that create files in /shared/data/.
If the Watchdog script is running only on m1, it detects changes to the directory in the share - but only if the files are created by processes from machine m1.
If processes from machine m2 creates files in the share, WatchDog does not detect the change.
I would like only one Watchdog based process on just machine m1 to detect files created by processes on /shared/data from any other machine.
The code I am using is below. Any suggestions appreciated.
import time
from watchdog.observers.polling import PollingObserver
from watchdog.events import FileSystemEventHandler
class OnMyWatch:
# Set the directory on watch
watchDirectory = "/shared/data"
def __init__(self):
self.observer = PollingObserver()
def run(self):
event_handler = Handler()
self.observer.schedule(event_handler, self.watchDirectory, recursive = True)
self.observer.start()
try:
while True:
print("Waiting...")
time.sleep(5)
except:
self.observer.stop()
print("Observer Stopped")
self.observer.join()
class Handler(FileSystemEventHandler):
@staticmethod
def on_any_event(event):
print(f"Event received.{event.event_type}, {event.src_path}")
if __name__ == '__main__':
watch = OnMyWatch()
watch.run()