April 12, 201412 yr I am trying to make a script that will run in cron once per week at 630AM once per week that looks at several folders and deletes anything older than either 1 week or 1 month. I also understand that I have to add the to my go script so it can persist after reboot. I know this is going to sound like a very dumb question, but I am trying to write the script and I just want someone to make sure it's correct before I change anything. This is what I have so far: file is named /boot/config/cronshowautodelete #!/bin/bash find /mnt/user/media/TV Shows/Law & Order Special Victims Unit/* -type d -ctime +30 -exec rm -rf {} \; find /mnt/user/media/TV Shows/CSI Crime Scene Investigation/* -type d -ctime +30 -exec rm -rf {} \; find /mnt/user/media/TV Shows/Parks and Recreation/* -type d -ctime +30 -exec rm -rf {} \; find /mnt/user/media/TV Shows/Community/* -type d -ctime +30 -exec rm -rf {} \; find /mnt/user/media/TV Shows/Real Time with Bill Maher/* -type d -ctime +30 -exec rm -rf {} \; find /mnt/user/media/TV Shows/The Colbert Report/* -type d -ctime +7 -exec rm -rf {} \; find /mnt/user/media/TV Shows/The Daily Show with John Stewart/* -type d -ctime +7 -exec rm -rf {} \; I guess my 4 questions are: 1. Is the script above OK with the current spacing in the directory names? And this will also delete all files and directories in this path recursively? This will be my first script, apologies for my ignorance. 2. How do I make this a cron job for the above mentioned time? 3. How do I add this to the go script for persistence? 4. Would anyone be interested in implementing an addon that can be handled through the webGUI that allows you to pick directory names and how much time to keep them with drop downs or something so it's extremely easy? Maybe with a few other options or rules as well? I'm not "completely" new to linux and I've always been able to muddle my way through, and unRAID has been a blessing for me. I have a home server that is functioning really well, and was very easy to configure and install thanks to the webGUI. The more options you can have for things like this, the more popular unRAID will get. Thanks for all the awesome work this community is doing! I'm going to preach unRAID from high on the mountain!
April 12, 201412 yr 1. Is the script above OK with the current spacing in the directory names? And this will also delete all files and directories in this path recursively? This will be my first script, apologies for my ignorance. As written the spaces in directory names will be treated as parameter separators. You either need to escape the spaces (e.g. '\ ') or put quotes around the name containing spaces. Since you also want wildcards I think you need to use the escape method.
April 12, 201412 yr Author So how would you rewrite one of those lines? And how to add is as a cron job and how to put it into the go script?
April 13, 201412 yr I'm FAR FROM a Bash guru, so I'm sure there are more elegant ways to accomplish this, but here's what I've got... In my case, I have some shows that I only want to keep the past 2 weeks of, and others that I only want the past 30 days of. #!/bin/bash ##Deleting any episodes older than 2 weeks: find /mnt/user/TV/Jimmy\ Kimmel\ Live/* -type f \( ! -iname "season*.tbn" -and ! -iname "folder.jpg" \) -ctime +15 -exec rm -rf {} \; find /mnt/user/TV/The\ Tonight\ Show\ Starring\ Jimmy\ Fallon/* -type f \( ! -iname "season*.tbn" -and ! -iname "folder.jpg" \) -ctime +15 -exec rm -rf {} \; find /mnt/user/TV/Late\ Night\ with\ Seth\ Meyers/* -type f \( ! -iname "season*.tbn" -and ! -iname "folder.jpg" \) -ctime +15 -exec rm -rf {} \; find /mnt/user/TV/Late\ Show\ with\ David\ Letterman/* -type f \( ! -iname "season*.tbn" -and ! -iname "folder.jpg" \) -ctime +15 -exec rm -rf {} \; find /mnt/user/TV/The\ Late\ Late\ Show\ with\ Craig\ Ferguson/* -type f \( ! -iname "season*.tbn" -and ! -iname "folder.jpg" \) -ctime +15 -exec rm -rf {} \; find /mnt/user/TV/Conan\ \(2010\)/* -type f \( ! -iname "season*.tbn" -and ! -iname "folder.jpg" \) -ctime +15 -exec rm -rf {} \; find /mnt/user/TV/The\ Colbert\ Report/* -type f \( ! -iname "season*.tbn" -and ! -iname "folder.jpg" \) -ctime +15 -exec rm -rf {} \; find /mnt/user/TV/The\ Daily\ Show\ with\ Jon\ Stewart/* -type f \( ! -iname "season*.tbn" -and ! -iname "folder.jpg" \) -ctime +15 -exec rm -rf {} \; ##Deleting any episodes older than 30 days: find /mnt/user/TV/Last\ Week\ Tonight\ with\ John\ Oliver/* -type f \( ! -iname "season*.tbn" -and ! -iname "folder.jpg" \) -ctime +30 -exec rm -rf {} \; find /mnt/user/TV/The\ Daily\ Show\ with\ Jon\ Stewart/* -type f \( ! -iname "season*.tbn" -and ! -iname "folder.jpg" \) -ctime +30 -exec rm -rf {} \; find /mnt/user/TV/The\ Soup/* -type f \( ! -iname "season*.tbn" -and ! -iname "folder.jpg" \) -ctime +30 -exec rm -rf {} \; find /mnt/user/TV/Real\ Time\ with\ Bill\ Maher/* -type f \( ! -iname "season*.tbn" -and ! -iname "folder.jpg" \) -ctime +30 -exec rm -rf {} \; ##Cleaning XBMC libraries: curl --data-binary '{ "jsonrpc": "2.0", "method": "VideoLibrary.Clean", "id": "mybash"}' -H 'content-type: application/json;' http://192.168.0.31:8080/jsonrpc > /dev/null 2>&1 curl --data-binary '{ "jsonrpc": "2.0", "method": "VideoLibrary.Clean", "id": "mybash"}' -H 'content-type: application/json;' http://192.168.0.10:8080/jsonrpc > /dev/null 2>&1 Note the escape characters in the directory names. I use a -type f in the find because I only want to delete files, not directories. I only want this to delete episode files, their .nfos and the related thumbnails, so I exclude the season.tbn and folder.jpg that Sickbeard creates. I also clean the libraries of my 2 XBMC boxes when done. Someday I should really get on the SQL bandwagon so I have a single repository for the XBMC library. I store this script in the root of flash (/boot). I added this to my go file to copy the script to /etc/cron.weekly/. Cron by default runs the contents of this dir every Sunday at 4:30 am: cp /boot/talkshowautodelete.sh /etc/cron.weekly/
April 13, 201412 yr Author No thank you so much! This is pretty damn close to what I am trying to do. I can redo the directory names like this, and I can leave the * and commands as they are I believe because I DO want to delete directories and everything else. And you're saying adding that putting a line similar to that in my go script and putting the file in cron.weekly will run sunday at 430am, which is fine as far as timing goes. I see the last two lines are removing the library info from XBMC. I don't know exactly why, but mine seems to update and remove broken links without having to do this. Right now I'm using a program called belvedere on another computer to clean the files, so if I can get this working I'm not dependent on another computer. Does this file in cron.weekly have to have any particular extension? Or just be chmodded to be executable and it will run?
April 13, 201412 yr Author Got it all working! Thanks so much for the help. Am I the only one who thinks this could be much easier using drop down menus through the GUI?! There HAVE to be other people who want their deleting automated and aren't linux experts and want to try unRAID. It seems pretty simple.
April 13, 201412 yr Does this file in cron.weekly have to have any particular extension? Or just be chmodded to be executable and it will run? Mine is a .sh, which is typical for a Bash script. chmod + x is required to make it executable.
Archived
This topic is now archived and is closed to further replies.