3

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

Krisztian
  • 383
  • 3
  • 9
  • That is `bash` not `batch`. Infact its not even `bash`, its `sh` –  May 11 '15 at 12:01
  • Is replacing the inotifywait call for a while loop, sleeping 10 seconds each time, an option? Than you can write a script that stops sleeping once a day and restart by cron. – Walter A May 11 '15 at 15:20
  • @JID: Thanks, I corrected it. But I wanted to refer to that we can use features in bash (even in v4.x). Walter A: it wouldn't be an ideal option, since the inner script would run in every 10 sec. – Krisztian May 12 '15 at 10:21

0 Answers0