inotifywait: new event triggered while processing the older one

278 views Asked by At

I have the following loop:

while inotifywait -qq --event close_write "$filebs" "$filevp"; do
    do_something()
done

The problem is that, at certain times, two events are triggered one right after the other, so that while the code is do_something() the first event, the second event is triggered.

Now, I'm fine with processing both events, and I'm fine with processing just the second event. But I'm not fine with processing just the first event.

How can I process them both?

I guess I need to print the events in a buffer, for e.g. with inotifywatch, and read from that buffer?

1

There are 1 answers

0
Brent Phillips On

I could be wrong but I think this will run on every event because I think that in your example you are restarting inotifywait after every event? -m, --monitor Instead of exiting after receiving a single event, execute indefinitely. The default behaviour is to exit after the first event occurs.

inotifywait -m -qq --format '%f' -e close_write "$filebs" "$filevp" | while read file
do


 echo "$file"
done