I came to this post (Monitor folder and run command if there is a file there?) about monitoring folders and then execute an action on found files. Everything works, but now I want to add a ".tmp" extension while files are being moved and then removing the .tmp extension again. However, instead of first moving to a .tmp file it moves the file back to a .mkv file.
So lets say I do:
cp /home/j-j/test/move_script/tv/tv_s01e01.mkv /home/j-j/test/move_script/transcoded_tv/
- tv_s01e01.mkv is being copied to transcoded_tv
- meanwhile tv_s01e01.mkv is recognised by inotifywait
- file is copied to watched_tv as tv_s01e01.mkv instead of to tv_s01e01.mkv.tmp first.
The solution is probably something easy, but can't find the solution. If anyone can help me? Below you can find the script.
#!/bin/bash
## set path to watch
movies="/home/j-j/test/move_script/transcoded_movies"
tv="/home/j-j/test/move_script/transcoded_tv"
set path to copy the script to
watchedMovies="/home/j-j/test/move_script/watched_movies"
watchedTv="/home/j-j/test/move_script/watched_tv"
Inotify Monitor
inotifywait -m -r -e moved_to -e create "$movies" "$tv" --format "%f" | while read f
Inotify Daemon
inotifywait -d -r -e moved_to -e create "$movies" "$tv" --format "%f" | while read f
do
echo $f
shopt -s nocasematch
check if file is a tv show
if [[ $f == *S[0-9][0-9]E[0-9][0-9]* ]] ; then
mediaType=$tv
watchedDir=$watchedTv
file is a movie
else
mediaType=$movies
watchedDir=$watchedMovies
fi
check if the file is not a cache file and is a .mkv file
if [[ $f != *TdarrCacheFile* ]] && [[ $f = *.mkv ]] ; then
creating temporary file first and then revert to mkv
mv "$mediaType/$f" "$watchedDir/$f.tmp" && mv "$watchedDir/$f.tmp" "$watchedDir/$f"
and rum it
/bin/bash "$watchedDir/$f" &
fi
done