1

I want to use inotifywait to monitor a special folder to convert the files with HandBrake. I move the file in the monitor_folder manualy.

The simple script look like this:

inotifywait -mrq -e moved -e create --format %f /media/user/monitor_folder | while read FILE
do
    sleep 2
    HandBrakeCLI -i /media/user/monitor_folder/$FILE -o /media/user/finished/$FILE -e x264 -q 20 -B 160
done

That works fine as long I put every file in the monitored folder after each convertion from HandBrake.

inotifywait seems not to monitor the folder while HandBrake works. Even if I put two files at the same time in the monitored folder : only the first is file is converted by HandBrake.

How can I monitor the folder to queue it with Handbrake?

BTW: the real script is much longer on the command is not just a singe line.

Gurkenglas
  • 33
  • 4
  • The script shown shall work regardless of the time of each move (since `inotifywait` runs in parallel with the loop body), and it works for me (after changing `moved` to `move`); so, your error must be in _the real script_. – Armali Feb 20 '18 at 12:03

1 Answers1

0

This is what I think will help you before reading below: How to execute a command whenever a file changes.

Have you thought about using

-d, --daemon

Same as --monitor, except run in the background logging events to a file that must be specified by --outfile. Implies --syslog.

Instead of

-m, --monitor

Instead of exiting after receiving a single event, execute indefinitely. The

default behaviour is to exit after the first event occurs.

This would allow you to check the files picked up by inotifywait

Also

-r, --recursive

Watch all subdirectories of any directories passed as arguments. Watches will be set up recursively to an unlimited depth. Symbolic links are not traversed. Newly created subdirectories will also be watched.

Warning: If you use this option while watching the root directory of a large tree, it may take quite a while until all inotify watches are established, and events will not be received in this time. Also, since one inotify watch will be established per subdirectory, it is possible that the maximum amount of inotify watches per user will be reached. The default maximum is 8192; it can be increased by writing to /proc/sys/fs/inotify/max_user_watches. " Ref inotifywait

However, robust applications should allow for the fact that bugs in the monitoring logic or races of the kind described below may leave the cache inconsistent with the filesystem state. It is probably wise to do some consistency checking, and rebuild the cache when inconsistencies are detected.

Ref inotify

halfer
  • 19,824
  • 17
  • 99
  • 186
  • [Michael Kerrisk](https://lwn.net/Articles/605128/) provides further description on the gotchas and corner cases. Thanks to him that there's [fluffy](https://github.com/tinkershack/fluffy#why-fluffy) which handles these cases gracefully. – six-k Mar 18 '18 at 17:47