I have a little script that tracks files for changes withinotifywait . When something changes, a package of files is sent through a process (compiled, compressed, reorganized, etc.), which takes about ten seconds to complete.
Consider the following example:
touch oli-test
inotifywait -mq oli-test | while read EV; do sleep 5; echo "$EV"; done
If you run touch oli-testseveral times in another terminal, you will see that each cycle ends before it moves. This scenario is very real to me. If I forget to save the file during its processing or notice an error, the events add up and I wait a minute.
It seems to me that there are two methods that will make this workflow objectively better. I'm not sure which is easier or better, so I present both:
Abort previous runs and restart immediately. Currently, the scripting process is only a built-in set of commands. I could break them down into Bash functions, I'm not alone to break them further than that.
Discard the list of pending events so that if five events occur immediately (or while they are already being processed), it will be triggered again.
(Or both ... because I'm sure there are times when both will be useful)
I am also open to approaches other than inotifywait, but they should give me the same result and work on Ubuntu.
source
share