Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- set -u
- declare -r username='transmission'
- declare -r password='transmission'
- declare -r download_dir='/var/lib/transmission-daemon/downloads'
- declare -t log='/var/log/transmission-purge.log'
- log()
- {
- local timestamp="$(/bin/date +'%Y-%m-%dT%H:%M:%S%z')"
- local level="$1"
- shift 1
- printf "%s - %s - %b\n" "$timestamp" "$level" "$@" | \
- /usr/bin/tee -a "$log" >&2
- }
- log_info()
- {
- log 'INFO' "$@"
- }
- log_error()
- {
- log 'ERROR' "$@"
- }
- die()
- {
- log 'ERROR' "$@"
- exit 1
- }
- log_info '----------------------------------------'
- trap 'log_info "----------------------------------------"' \
- HUP INT TERM EXIT
- if [ ! -d "$download_dir" ]; then
- die "Transmission download directory '$download_dir' not found"
- fi
- log_info "List tasks"
- output="$(transmission-remote -n "$username":"$password" -l)"
- status=$?
- log_info "Tasks\n$output"
- if [ $status -ne 0 ]; then
- die "Failed to list tasks, status: $status"
- fi
- log_info "Check orphan files"
- /bin/ls -1 "$download_dir" | \
- while IFS='' read -r line || [[ -n "$line" ]]; do
- case $output in
- *"$line"*) ;;
- *) log_info "Orphan: ${download_dir}/${line}" ;;
- esac
- done
- log_info "Free Spaces\n$(df -h /)"
Add Comment
Please, Sign In to add comment