Last active
July 20, 2025 08:32
-
-
Save Mageas/5a20163d6aecfe3919d09fd6f01beaf1 to your computer and use it in GitHub Desktop.
Remove empty jellyfin Shows & remove plex hard links
This file contains hidden or 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 | |
| PARENT_DIRS=("Shows" "Movies") | |
| prefix="[$(date '+%Y-%m-%d %H:%M')]" | |
| script_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
| if [[ -z "${script_path}" || "${script_path}" == "/" || ! -d "${script_path}" ]]; then | |
| echo "${prefix} ERROR: Invalid script path: ${script_path}" | |
| exit 1 | |
| fi | |
| cd "${script_path}" | |
| check_forbidden_files() { | |
| find "${1}" -type f \ | |
| ! -iname "*.jpg" \ | |
| ! -iname "*.png" \ | |
| ! -iname "*.svg" \ | |
| ! -iname "*.nfo" \ | |
| | wc -l | |
| } | |
| for ROOT_DIR in "${PARENT_DIRS[@]}"; do | |
| [[ ! -d "${ROOT_DIR}" ]] && continue | |
| find "${ROOT_DIR}" -mindepth 1 -maxdepth 1 -type d | while read -r current_dir; do | |
| if [[ $(check_forbidden_files "${current_dir}") -eq 0 ]]; then | |
| echo "${prefix} Removing : ${current_dir}" | |
| rm -rf "${script_path}/${current_dir}" | |
| fi | |
| done | |
| done |
This file contains hidden or 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 | |
| PARENT_DIRS=("radarr" "tv-sonarr") | |
| DISCORD_WEBHOOK_URL="" | |
| MIN_AGE_MINUTES=120 | |
| prefix="[$(date '+%Y-%m-%d %H:%M')]" | |
| script_path="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | |
| if [[ -z "${script_path}" || "${script_path}" == "/" || ! -d "${script_path}" ]]; then | |
| echo "${prefix} ERROR: Invalid script path: ${script_path}" | |
| exit 1 | |
| fi | |
| cd "${script_path}" | |
| declare -a DIRS_TO_DELETE=() | |
| count_media_files() { | |
| find "${1}" -type f \ | |
| ! -iname "*.jpg" \ | |
| ! -iname "*.png" \ | |
| ! -iname "*.svg" \ | |
| ! -iname "*.nfo" \ | |
| | wc -l | |
| } | |
| count_media_files_hard_links() { | |
| find "${1}" -type f \ | |
| -links 1 \ | |
| ! -iname "*.jpg" \ | |
| ! -iname "*.png" \ | |
| ! -iname "*.svg" \ | |
| ! -iname "*.nfo" \ | |
| | wc -l | |
| } | |
| for ROOT_DIR in "${PARENT_DIRS[@]}"; do | |
| [[ ! -d "${ROOT_DIR}" ]] && continue | |
| while IFS= read -r current_dir; do | |
| media_files="$(count_media_files "${current_dir}")" | |
| media_files_hard_links="$(count_media_files_hard_links "${current_dir}")" | |
| if [ "${media_files}" -gt 0 ] && [ "${media_files_hard_links}" -ge "${media_files}" ]; then | |
| echo "${prefix} Removing : ${current_dir}" | |
| rm -rf "${current_dir}" | |
| DIRS_TO_DELETE+=("${current_dir}") | |
| fi | |
| done < <(find "${ROOT_DIR}" -mindepth 1 -maxdepth 1 -type d -mmin +${MIN_AGE_MINUTES}) | |
| done | |
| if [ ${#DIRS_TO_DELETE[@]} -gt 0 ]; then | |
| dir_list_string="" | |
| for dir in "${DIRS_TO_DELETE[@]}"; do | |
| dir_list_string+="- $(basename "${dir}")" | |
| dir_list_string+=$'\n' | |
| done | |
| description_body=$(printf "**%s torrents(s)** à supprimer :\n\n%s" "${#DIRS_TO_DELETE[@]}" "${dir_list_string}") | |
| JSON_PAYLOAD=$(jq -n \ | |
| --arg title "🧹 Rapport de Nettoyage Automatique" \ | |
| --arg desc "$description_body" \ | |
| --arg footer_text "Netflox - nettoyage automatique" \ | |
| --arg timestamp "$(date -u +'%Y-%m-%dT%H:%M:%SZ')" \ | |
| '{ | |
| "embeds": [ | |
| { | |
| "title": $title, | |
| "description": $desc, | |
| "color": 3066993, | |
| "footer": { "text": $footer_text }, | |
| "timestamp": $timestamp | |
| } | |
| ] | |
| }') | |
| curl -H "Content-Type: application/json" -X POST -d "${JSON_PAYLOAD}" "${DISCORD_WEBHOOK_URL}" | |
| fi |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add crontab
Open crontab :
Crontab command (execute every 5 minutes) :