Cleanup Logs from /opt/appdata [ crontab | bash file ]

here a small script to cleanup the server from log files in /opt/appdata

for sonarr [ 4k / hdr / normal ] or radarr { 4k / hdr / normal ] and traktarr [ 4k / hdr / normal ]

#!/usr/bin/with-contenv bash
# shellcheck shell=bash
# Copyright (c) 2020, MrDoob
# All rights reserved.
mapfile -t arr < <(eval docker ps -aq --format '{{.Names}}' | sed '/^$/d' | grep -E 'arr')
for i in ${arr[@]}; do
  mapfile -t folder < <(eval find /opt/appdata/$i -type d -name 'logs')
  for ii in ${folder[@]}; do
    find $ii -type f -name "*.txt**" -delete 1>/dev/null 2>&1
  done
done
sudo crontab -e 

add follow line

@daily bash /path/to/file.sh 1>/dev/null 2>&1

here a one liner for crontab to cleanup qbittorrent logs

sudo crontab -e

add follow line

### cleanup logs from qBittorrent
@daily find /opt/appdata/qbittorrent/qBittorrent/logs -type f -name "*.bak**" -delete

here a on line to cleanup nzbget logs

sudo crontab -e

add follow line

### cleanup logs from nzbget
@daily truncate -s 0 /opt/appdata/nzbget/nzbget.log 1>/dev/null 2>&1

here a on line to cleanup sabnzbd logs

sudo crontab -e

add follow line

### cleanup logs from sabnzbd
@daily truncate -s 0  /opt/appdata/sabnzbd/logs/sabnzbd.log 1>/dev/null 2>&1

the top one can be expanded

1 Like