I apologize for the necro, but I'm sure people are stumbling across this thread just as I did and I think I can contribute some useful knowledge.
The "search and destroy" functionality - searching out the recycle bin and purging it - is pretty straightforward and can be done with a wildcard.
Code:
find /mnt/tank/*/.recycle/* -atime +30 -delete
This command will find any folder named .recycle anywhere in the "tank" dataset regardless of share and delete everything in it older than 30 days. The threshold is determined by the atime flag and can be changed to your desires. You may also note that instead of running rm -rf everywhere, I'm using the -delete flag. Both will work, but having a script going around running rm -rf makes me a little uneasy, so I prefer not to do it. Before running this for the first time, I would also recommend opening up ssh and running the command
without the -delete flag; the output should be a list of files that meet the criteria for deletion and looking over these now could save you a ton of snapshot rollbacks later. Note that if you're getting an error about "no such directory," it's likely because the .recycle directory is deeper in the directory structure; "*" will only expand to a single level of the structure, so in the example above we're looking inside every folder in "tank" for a folder named ".recycle" and if ".recycle" happens to be in a subfolder, find won't see it.
The second command doesn't need much tweaking, but I would again use the -delete flag instead of rm -rf. Additionally, removing the -depth flag will make it also evaluate the .recycle directory itself and remove that if it's empty as well.
My final note is that a script for two lines just isn't necessary. All *nix operating systems can fit as many commands as you want on a single line and, while not practical for longer functions, with just two commands it's worth it in order to avoid having to save the script somewhere and having to use something other than the freenas web ui to edit it. By simply putting
Code:
find /mnt/tank/*/.recycle/* -atime +30 -delete; find /mnt/*/.recycle/ -type d -empty -delete
in the command field of the cron job, we can find all recycle bins in all shares, delete any contents over 30 days old, remove all empty directories within the recycle bin, and then remove the .recycle folder itself if there's nothing in it.