Last active
October 16, 2023 21:24
-
-
Save acouvreur/25f90a605307705cd71c9399fa7eb5b8 to your computer and use it in GitHub Desktop.
Sync deleted files from Radarr/Sonarr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Find existing files in download/complete that are not in movies or tvshows. | |
export DOWNLOAD_FOLDER=path/to/downloads | |
export MOVIES_FOLDER=path/to/movies | |
export TVSHOWS_FOLDER=path/to/tvshows | |
findExistingFile() { | |
file=$(find $MOVIES_FOLDER/ $TVSHOWS_FOLDER/ -samefile "$1") | |
if [ -z "$file" ]; then | |
echo "File \"$1\" is not present in the movies or tvshows folders. Deleting..." | |
rm "$1" | |
fi; | |
} | |
export -f findExistingFile | |
find $DOWNLOAD_FOLDER -type f -size +1G -exec bash -c 'findExistingFile "$0"' {} \; |
Hey, about this code, i have a path with spaces and when i used " " that used only the one word you know why and how to fix it ?
I just added quotes around the rm
command argument. Does that works for you @hrb9 ?
You need to put quotes around all the variables for it to work:
#!/bin/bash
# Find existing files in download/complete that are not in movies or tvshows.
export DOWNLOAD_FOLDER="path/to/downloads"
export MOVIES_FOLDER="path/to/movies"
export TVSHOWS_FOLDER="path/to/tvshows"
findExistingFile() {
file=$(find "$MOVIES_FOLDER"/ "$TVSHOWS_FOLDER"/ -samefile "$1")
if [ -z "$file" ]; then
echo "File \"$1\" is not present in the movies or tvshows folders. Deleting..."
rm "$1"
fi;
}
export -f findExistingFile
find "$DOWNLOAD_FOLDER" -type f -size +1G -exec bash -c 'findExistingFile "$0"' {} \;
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, about this code, i have a path with spaces and when i used " " that used only the one word you know why and how to fix it ?