LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   inotifywait only in specific dir, specific type of file (https://www.linuxquestions.org/questions/linux-newbie-8/inotifywait-only-in-specific-dir-specific-type-of-file-4175605841/)

mackowiakp 05-13-2017 10:15 AM

inotifywait only in specific dir, specific type of file
 
I spent a lot of time but no lucky.
I want to trigger action when in specific dir (and only in that dir) will be new file. This dir contains films so transmission of such file take several minutes. It could be MKV or MP4 file. I want to trigger action when file will be closed, that is transmission ends. Other types of files in this dir should be ignored by inotifywait.
Any advice how looks like proper syntax of such inotifywait command?

JeremyBoden 05-13-2017 10:23 AM

See https://linux.die.net/man/1/inotifywait

mackowiakp 05-13-2017 10:44 AM

I read it but if I want specify wildcards in filename (like *.mkv) it does not work. Look at the command line I use. Where is an error?

Code:

inotifywait -e close_write /path_to_dir/*.mkv

michaelk 05-13-2017 10:47 AM

Although you should be able to find some examples here is a basic bash script to watch a directory. You can add code to test for mkv or mk4 extension.

Code:

#!/bin/bash
/usr/bin/inotifywait -mq -e close_write --format %f /dir/to/watch | while IFS= read -r file; do
  echo $file
  Do something constructive here...
done

Your command fails because you can not watch something that does not already exist as far as I know.


All times are GMT -5. The time now is 11:20 PM.