Skip to content

Instantly share code, notes, and snippets.

@Mageas
Last active February 6, 2025 20:22
Show Gist options
  • Save Mageas/5a20163d6aecfe3919d09fd6f01beaf1 to your computer and use it in GitHub Desktop.
Save Mageas/5a20163d6aecfe3919d09fd6f01beaf1 to your computer and use it in GitHub Desktop.
Remove empty jellyfin Shows
#!/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
@Mageas
Copy link
Author

Mageas commented Jan 5, 2025

Add crontab

Open crontab :

crontab -e

Crontab command (execute every 5 minutes) :

*/5 * * * * /home/path/to/file/clean.sh > /home/path/to/file/clean.log

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment