Initialize source and destination directories.
srcdir=/user/user1/src
tagtdir=/user/user1/dest
I would like to get notified when a file is copied over into the srcdir and -m
for continuous monitoring.
inotifywait -m -r -e close "$srcdir" |
while read filename eventlist eventfile
Invoke my python script.
do
mv "$srcdir/$eventfile" "$tgtdir/$eventfile" && ./myscript.py "$eventfile"
done
Unfortunately, my script that quite some time and if there are other files being copied over while myscript.py
is being executed, I miss those events. Is it possible to queue up the events and process them later?
Another option is I will run myscript.py
in background and that might solve this issue.
You can use Watchman instead; it runs as a persistent service and will remember the events that you missed.
There are a number of different ways that you might achieve your use-case, but probably the easiest is to set up a trigger and have watchman directly run your script as files change, or use the pywatchman client bindings to have a persistent python script run and subscribe to the events and take whatever action you'd like.