Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: Script to clean recycle bins

  1. #1
    Join Date
    Nov 2011
    Beans
    12

    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.

  2. #2
    Join Date
    May 2007
    Location
    Leeds, UK
    Beans
    1,664
    Distro
    Ubuntu 13.10 Saucy Salamander

    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.

  3. #3
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,445
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: Script to clean recycle bins

    -exec rm is not necessary, you can use -delete flag
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  4. #4
    Join Date
    Nov 2011
    Beans
    12

    Re: Script to clean recycle bins

    I have tried both of your suggestions, still the same response occurs.

  5. #5
    Join Date
    May 2006
    Location
    Milwaukee,WI
    Beans
    6,282
    Distro
    Xubuntu 14.04 Trusty Tahr

    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 {} \;

  6. #6
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,445
    Distro
    Ubuntu 14.04 Trusty Tahr

    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
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

  7. #7
    Join Date
    Nov 2011
    Beans
    12

    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] #

  8. #8
    Join Date
    May 2006
    Location
    Milwaukee,WI
    Beans
    6,282
    Distro
    Xubuntu 14.04 Trusty Tahr

    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

  9. #9
    Join Date
    Jun 2008
    Location
    Tennessee
    Beans
    3,421

    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?

  10. #10
    Join Date
    Jul 2007
    Location
    Poland
    Beans
    4,445
    Distro
    Ubuntu 14.04 Trusty Tahr

    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.
    if your question is answered, mark the thread as [SOLVED]. Thx.
    To post code or command output, use [code] tags.
    Check your bash script here // BashFAQ // BashPitfalls

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •