Setting up watch folder, watching for new files in folder


Recommended Posts

Hi

 

I'm trying to setup a watch folder that will run a command whenever I add a file to that folder over SMB, I got it somewhat working, but I still have some problems with timing (or multiple runs on the same file).

 

The script is supposed to convert any mkv or avi file I add to the folder into an MP4 using Don Melton's transcode-video script (For which a docker container have already been created. The idea is, that I can just convert my DVDs to MKV files and dump them onto the server for automatic processing.

 

This is what I currently have:

inotifywait -m -r convert_movies -e close_write |
    while read path action file; do
        echo "The file '$file' appeared in directory '$path' via '$action'"
if [[ $file =~ .*\.(mkv|avi) ]]; then
	#docker run --rm -it -v /mnt/user/Misc/convert_movies:/data ntodd/video-transcoding transcode-video --crop detect --mp4 "$(echo $path | sed 's/convert_movies\///g')$file"
	echo "File $file was written to $(echo $path | sed 's/convert_movies\///g')$file, converting..."
fi 
    done

 

I commented out the docker run command, for testing that the script actually work.

 

The problem is, that every time I add a file, I get multiple "close_write" triggers:

The file 'test.mkv' appeared in directory 'convert_movies/test/' via 'CLOSE_WRITE,CLOSE'
File test.mkv was written to test/test.mkv, converting...
The file 'test.mkv' appeared in directory 'convert_movies/test/' via 'CLOSE_WRITE,CLOSE'
File test.mkv was written to test/test.mkv, converting...

 

I'm not really sure how to avoid this, or if there is something better than using inotifywait for the trigger, I would really appreciate if someone could help me getting this to work correctly.

Link to comment
  • 3 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.