Script to clean recycle bins
I have a qnap TS259 that runs ubuntu. I am trying to create a script that would clean up the recycle bin's for everything older than 3 months, by default the web GUI of the administration page does it every 12 months.
here is the script I have currently:
Code:
#!/bin/sh
####################################
#
# simple script that will walk thru the
# recycle bins on NAS and delete everything
# older than 90 days
#
####################################
/usr/bin/find /share/HDA_DATA/"Network Recycle Bin"/*.* -mtime +90 -rm {} \;
here is the response when I try to run it:
Code:
[/share/Data/templates] # ./cleanrecyclebin.sh
BusyBox v1.01 (2012.12.04-18:29+0000) multi-call binary
Usage: find [PATH...] [EXPRESSION]
Search for files in a directory hierarchy. The default PATH is
the current directory; default EXPRESSION is '-print'
EXPRESSION may consist of:
-follow Dereference symbolic links.
-name PATTERN File name (leading directories removed) matches PATTERN.
-print Print (default and assumed).
-type X Filetype matches X (where X is one of: f,d,l,b,c,...)
-perm PERMS Permissions match any of (+NNN); all of (-NNN);
or exactly (NNN)
-mtime TIME Modified time is greater than (+N); less than (-N);
or exactly (N) days
[/share/Data/templates] #
Any help greatly appreciated.
Re: Script to clean recycle bins
I think you need something more like:
Code:
/usr/bin/find /share/HDA_DATA/"Network Recycle Bin"/ -mtime +90 -exec rm {} \;
It's always safest to try the command with -print instead of the -exec before commiting to deletion of course. You'll need a recursive delete and -f flag to handle directories which starts to get dangerous if it goes wrong.
Re: Script to clean recycle bins
-exec rm is not necessary, you can use -delete flag
Re: Script to clean recycle bins
I have tried both of your suggestions, still the same response occurs.
Re: Script to clean recycle bins
i believe it's because you have spaces in your directories name, you need to include the entire path within the quotes or escape the spaces with \ example:
Code:
/usr/bin/find "/share/HDA_DATA/Network Recycle Bin/*.*" -mtime +90 -rm {} \;
OR
Code:
/usr/bin/find /share/HDA_DATA/Network\ Recycle\ Bin/*.* -mtime +90 -rm {} \;
Re: Script to clean recycle bins
looks like that version of find is pathetic compared to the gnu find (my gut feeling based on googled http://forum.qnap.com/viewtopic.php?t=23780).
you have two choices:
- install gnu version
- use only mtime (it supposedly works) and then iterate the output, eg
Code:
find ... | while read -r f; do rm "$f"; done
Re: Script to clean recycle bins
Tried this ............
Code:
#!/bin/sh
####################################
#
# simple script that will walk thru the
# recycle bins on NAS and delete everything
# older than 90 days
#
####################################
find "/share/HDA_DATA/Network Recycle Bin/*" | while read -r f; do rm "$f"; done
And got this ......
Code:
[/share/Data/templates] # ./cleanrecyclebin.sh
find: /share/HDA_DATA/Network Recycle Bin/*: No such file or directory
[/share/Data/templates] #
Re: Script to clean recycle bins
is there a folder at that location? lol
Network Recycle Bin is not a folder that Ubuntu creates I know that much
Re: Script to clean recycle bins
Looks more like busybox find can't do globbing. Would leaving off the asterisk delete the trash bin directory?
Re: Script to clean recycle bins
* definitely needs to be outside the quotes to trigger globbing, wrapped in quotes it's just an ordinary char.