Skip to content
View in the app

A better way to browse. Learn more.

Unraid

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Sonarr Cleanup - unraid specific [SOLVED]

Featured Replies

Hi all. After countless times of checking settings (tried turning hardlinks off and turning them on, makes no difference) and many a google, for whatever reason my sonarr docker doesn't clean up downloads after importing. My radarr docker does just fine. This applies to both torrents and usenet functions. Wondering if i'm the only one experiencing this, but if not... How do you guys clean these folders up aside from manually going in and clearing downloads every week or two? anybody have a script for something like that?

Edited by Cpt. Chaz

  • 3 months later...
  • Author

Realize this is an old post of mine, but the problem persisted for me and i finally solved it. Below is the script I use to clean out my usenet completed downloads folder. It's set to clean out files older than 3 days, run daily. Maybe it can be useful for somebody

 

#!/bin/bash
echo "Searching for (and deleting) Files older than 3 Days"

echo "Should Only Take a Second"

#dir = WHATEVER FOLDER PATH YOU WANT CLEANED OUT
dir=/path/to/folder/

#ENTER NUMERIC VALUE OF DAYS AFTER "-MTIME +"
find $dir* -mtime +3 -exec rm -rfv {} \;

echo "Done for Now"

echo "See Ya Tomorrow"

 

Edited by Cpt. Chaz
syntax typo

  • 1 year later...

Hiya, 

 

I don't know linux well, but trying to use the above script kindly shared - I can't get it to work. Does this look right (to delete everything more than a day old):

 

#!/bin/bash
echo "Searching for (and deleting) Files older than 3 Days"

echo "Should Only Take a Second"

#dir = WHATEVER FOLDER PATH YOU WANT CLEANED OUT
dir=/mnt/user/downloads/incomplete

#ENTER NUMERIC VALUE OF DAYS AFTER "-MTIME +"
find $dir* -mtime +1 -exec rm -rfv {} \;

echo "Done for Now"

echo "See Ya Tomorrow"

 

...is my formatting of the directory ok?

Either the dir= line should end in a /  - look like this dir=/mnt/user/downloads/incomplete/   , OR the find command should include the slash:  $dir/* and look like - find $dir/* -mtime +1 -exec rm -rfv {} \;

Currently find is looking for files that start with incomplete in the downloads directory - in reality this: /mnt/user/downloads/incomplete* , notice the incomplete*. You have the two choices I mentioned to fix, do not use both.

give either of those a try, that should make it work.

Ah, fab - thank you. I've updated the location as you describe and also changed the time to zero as follows:

 

#dir = WHATEVER FOLDER PATH YOU WANT CLEANED OUT
dir=/mnt/user/downloads/incomplete/

#ENTER NUMERIC VALUE OF DAYS AFTER "-MTIME +"
find $dir* -mtime +0 -exec rm -rfv {} \;

 

However, it's still not deleting a test file I put there yesterday - any ideas?

 

Thanks! :)

+1, 1, and -1 also +0, 0, -0 all mean different things for mtime. But +0 will not make the mtime statement true, and will not return any files to the -exec command. Try below to see what I mean.

use this and test what changing the -mtime to those six values above. Then when this -exec ls -ltr {} \; brings back what you need then use that for the -mtime value. Test to be sure that it is doing *exactly* what you want before updating the script and and running for rm.


find  /mnt/user/downloads/incomplete/* -mtime <your test # here> -exec ls -ltr {} \;

 

*** Use at your own risk, not responsible for you using an incorrect -mtime value and removing more files than you intend. Be sure the ls -ltr {} \; is doing what you expect. ***

That makes total sense - and it now works (using "mtime +0" to clear the test file out). Every day is a school day!

 

This is an excellent little script that should save loads of time.

 

Thanks so much :)

  • Author

Glad you got it sorted @ThinkSta. minor oversight in posting the script on my part, as i have the "/" at the end of my directory in the original. devil is always in the details. Glad @klepel was able to help, i'll edit the OP to reflect what it should have been. Cheers!

 

  • 2 months later...

First time poster here. I just started using unRAID and so far absolutely love it. I'm coming from Synology, which is a great platform, but I love the ability to use my own hardware and the versatility of unRAID.

 

@Cpt. Chaz, this is a great script and just what I was looking for, so thank you.

 

I am relatively new to scripting, so I was hoping you or someone else could help with a modification to this script. How hard would it be to exclude specific files and folders? I have a hidden file and folder (i.e. .file and .folder) that I need to NOT delete.

 

Could someone point me in the right direction?

 

Thanks so much for your help!

 

Edited by DepthVader
Spelling

  • Author

Hi @DepthVader, sorry it took so long to get back to you. Not sure if you were able to solve this or not, but I admittedly had to do a little googling to find the answer. 
 

this forum here seems to show in good detail what you need. In case the link is broken in the future for anyone else coming across this post, here’s a snippet of the relevant text:

 

To exclude files and folders starting with “.” or “@“

 

find /path/to/start/search/ -not -path '*/[@.]*' -type f -mtime -2


So in your case, (since you don’t need to exclude the “@“) I think it would be something like:

find $dir* -not -path ‘*/[.]*’ -mtime +3 -exec rm -rfv {} \;


I have not personally tested this, so I don’t know for sure. Give this a try, make backups or use some test files/folders to be sure beforehand, and double check me. But I think this is it! Let me know how it goes. 

 

@Cpt. Chaz

 

Thank you for your research, I really appreciate it!  I have not had a chance to play with the script yet. Life got in the way...as it does...

 

My work is crazy right now, so I'm not sure when I'll get a chance to try this out (maybe this weekend). Once I get a chance to try it out, I'll post back my findings when I'm done for others.

 

If I end up tweaking your argument, I'll post what I did.

 

I'll also read the forum you linked to, to help educate myself. 

 

Thanks again for looking into this for me!

 

😁

On 3/16/2022 at 6:34 PM, Cpt. Chaz said:

 

find $dir* -not -path ‘*/[.]*’ -mtime +3 -exec rm -rfv {} \;


 

 

@Cpt. Chaz,

 

Sorry for the delayed response. I changed the -mtime to +1, thinking it would delete files over a day old....oops...it took two days (I understand why now, just didn't at the time), which delayed my response by a day. 🙃

 

Anyways....your above command worked perfectly!  It deleted all the files and folders, except the hidden ones!  

 

You are the best and thanks for all your help!

 

😁😁

  • Author

Awesome! Anytime 👍

  • 2 years later...

Hey Chaz, if you are still around some, do you think you could point me in the right direction to use multiple folders with this script?  I keep running in to errors and I'm not sure where I'm going wrong.  Thanks!

  • 2 months later...

Thanks for the script Cpt. Chaz!

I adjusted it for multiple directories, in case somebody needs it:

 

#!/bin/bash
echo "Searching for (and deleting) Files older than 3 Days"

echo "Should Only Take a Second"

# Array of directories to clean
directories=(
    "/mnt/user/Downloads/completed/f1/"
    "/mnt/user/Downloads/completed/f2/"
    "/mnt/user/Downloads/completed/f3/"
    # Add more directories as needed
)

# Iterate through each directory
for dir in "${directories[@]}"; do
    echo "Processing directory: $dir"
    find "$dir" -mtime +3 -exec rm -rfv {} +
done

echo "Done for Now"

echo "See Ya Tomorrow"

 

Edited by mattti

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.