cron jobs from the new GUI with file/dir exclusions

RegularJoe

Patron
Joined
Aug 19, 2013
Messages
330
Hi All,

It seems that cron or zsh is kicking my butt.

I never want to delete the file "File Exchange Area - 10 day storage.txt"
I never want to delete the folder "File Exchange Area - 10 day storage"
I only want to delete folders that are empty and older than 10 days
I do not want to delete a nested folders that have data

find /mnt/FileServerPub/shares/public -type f -mtime +10 -exec rm {} \;
find /mnt/FileServerPub/shares/public -type d -mtime +10 -exec rm {} \;

Is it better to just create a script, if so where to store the script so that upgrades do not delete it?

Thanks,
Joe
 

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
Upgrades shouldn't reset the crontab. Are you adding the task in the GUI? Or are you editing the crontab manually? (Don't do that.)

If you never want to delete that file or folder, you would need to have an exclusion for those in your find command.
You also don't need two commands if you're looking for files and directories.
Something like:
find /mnt/FileServerPub/shares/public -mtime +10 -not -name 'File Exchange Area - 10 day storage*' -exec rm {} \;

Please test before using
 

RegularJoe

Patron
Joined
Aug 19, 2013
Messages
330
I test with

find /mnt/FileServerPub/shares/public -mtime +10 -not -name 'File Exchange Area - 10 day storage*' -exec ls {} \;

LOL

I did make the mistake of trying " around the file area, maybe I need to just nix the spaces like a good file server user.
 

RegularJoe

Patron
Joined
Aug 19, 2013
Messages
330
I still ended up with 2 cron jobs, one to keep the files deleted and the other to delete the old recycle bin files

find /mnt/FileServerPub/shares/public -mtime +10 -not -name '_File_Exchange_Area_-_10_day_storage*' -not -path '*/.recycle*' -exec rm {} \;
find /mnt/FileServerPub/shares/public/.recycle -mtime +30 -exec rm {} \;
 

fracai

Guru
Joined
Aug 22, 2012
Messages
1,212
What was the issue with spaces? A problem passing to the rm command in -exec? I think you can easily work around that by using -delete instead. Though now I'm not sure if that's available in the version of find that is available.
 

RegularJoe

Patron
Joined
Aug 19, 2013
Messages
330
today I looked and I now have 3 cron jobs, one to delete empty folders. Since this is a public share I have to clean up after my users:

find /mnt/FileServerPub/shares/public -empty -type d -delete
 
Top