So, first let me give some background.
I have some security cameras that trigger on motion detection and dump an .avi file via ftp to my server.
I currently have a cron job, running every minute, to find all .avi files and then convert them to .mp4 and an animated .gif to show in an html gallery.
I wanted something more immediate, without having to scan all the directories for missing .avi files, so I tried to use inotifywait.... and found a problem. Each new day, on the first motion detected, a new folder is created with the current date, and inotifywait doesn't watch it. I have no idea when the folder is created, since it depends when (or if) there is motion captured by the camera.
So, my question, is there a way to refresh inotifywait and add missing folders or the only way to do this is to kill the process and restart it? Or, is there another way to achieve what I want, something more immediate than a find every minute?
EDIT: just a quick note, the reason why I wanted something faster is because with all the folders, find takes almost 30s just to scan the directories
-r
makes inotifywait watch newly created directories, example:
# mkdir /tmp/watch/
$ inotifywait -rm /tmp/watch/
Setting up watches. Beware: since -r was given, this may take a while!
Watches established.
# touch /tmp/watch/FILE
/tmp/watch/ CREATE FILE
/tmp/watch/ OPEN FILE
/tmp/watch/ ATTRIB FILE
/tmp/watch/ CLOSE_WRITE,CLOSE FILE
# mkdir /tmp/watch/dir
/tmp/watch/ CREATE,ISDIR dir
/tmp/watch/ OPEN,ISDIR dir
/tmp/watch/ ACCESS,ISDIR dir
/tmp/watch/ CLOSE_NOWRITE,CLOSE,ISDIR dir
# touch /tmp/watch/dir/FILE-IN-DIR
/tmp/watch/dir/ CREATE FILE-IN-DIR
/tmp/watch/dir/ OPEN FILE-IN-DIR
/tmp/watch/dir/ ATTRIB FILE-IN-DIR
/tmp/watch/dir/ CLOSE_WRITE,CLOSE FILE-IN-DIR
I have inotifywait 4.23.9.0 here but recursive option has been introduced in 2009 so it should be available and work the same way on all current systems.
Make sure to pass a correct root directory to inotifywait, if you want to observe a directory and sibling directories - that is directories on the same level of filesystem hierarchy you have to tell inotifywait to watch parent directory.