Cpt. Chaz Posted April 16, 2020 Share Posted April 16, 2020 (edited) 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 July 30, 2020 by Cpt. Chaz Quote Link to comment
Cpt. Chaz Posted July 30, 2020 Author Share Posted July 30, 2020 (edited) 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 December 17, 2021 by Cpt. Chaz syntax typo 1 1 Quote Link to comment
ThinkSta Posted December 17, 2021 Share Posted December 17, 2021 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? Quote Link to comment
-MacGyver- Posted December 17, 2021 Share Posted December 17, 2021 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. Quote Link to comment
ThinkSta Posted December 17, 2021 Share Posted December 17, 2021 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! Quote Link to comment
-MacGyver- Posted December 17, 2021 Share Posted December 17, 2021 +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. *** Quote Link to comment
ThinkSta Posted December 17, 2021 Share Posted December 17, 2021 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 Quote Link to comment
Cpt. Chaz Posted December 17, 2021 Author Share Posted December 17, 2021 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! Quote Link to comment
DepthVader Posted March 10, 2022 Share Posted March 10, 2022 (edited) 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 March 11, 2022 by DepthVader Spelling Quote Link to comment
Cpt. Chaz Posted March 17, 2022 Author Share Posted March 17, 2022 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. 1 Quote Link to comment
DepthVader Posted March 18, 2022 Share Posted March 18, 2022 @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! 😁 1 Quote Link to comment
DepthVader Posted March 23, 2022 Share Posted March 23, 2022 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! 😁😁 1 Quote Link to comment
Cpt. Chaz Posted March 23, 2022 Author Share Posted March 23, 2022 Awesome! Anytime 👍 1 Quote Link to comment
Recommended Posts
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.