There's a directory tree which is watched by inotifywait
. What I want to do is trigger a script (e.g. with which I can move the files from it) with a delay (e.g. 10sec), so this script won't be triggered at any event but in a "groupped" event.
The batch script (which is part of a bigger script, sending email at the end, etc.) moves files to the corresponding directory of an another directory manage_all.sh
:
#!/bin/bash
TEMPDIR="/mnt/foo/temp"
QUEUEDIR="/mnt/foo/queue"
SLOTSLEFTINQUEUE=5
for FILEPATH in $(ls -1tr $(find "$TEMPDIR" -type f -iname \*.txt) | head -n$SLOTSLEFTINQUEUE) ; do
FILESUBPATH="${FILEPATH#$TEMPDIR/}"
mv -f "$FILEPATH" "$QUEUEDIR/$FILESUBPATH"
done
This runs in cron now every 5 mins, and working great. But I want to use inotifywait
, not to wait for another 5 mins.
I have tried this, but it's not good, since it triggers the manage_all.sh
script with every event:
(echo start; inotifywait -mr -e close_write,moved_to,modify "/mnt/foo/temp") | while read line; do ./manage_all.sh; done
Is it possible (without rewriting the script) to "group events together" that will fire up the script only once in every 10 seconds?
Thanks