5 Replies Latest reply: Aug 3, 2012 10:20 AM by Camelot
scoryell Level 1 Level 1 (0 points)

Hi All,

 

I'm charged with keeping our server and files maintained at work, and they have asked if I can schedule a weekly/monthly cleaning of the drive that is being served. I'm more of a designer then tech support, can anyone give me some ideas how I might do this?

 

I have all access admin priv.

I do use a mac everyday and I am familiar with the OS.

We are using a Mac Mini running 10.6.8 with Server 10.5 installed.

I don't have any apple scripting experience but am willing to try.

 

Thanks  in advanced

Steve


Mac mini, Mac OS X (10.6.8), Server X 10.5 Installed
  • 1. Re: Schedule Clearing Files from a drive that is being served
    Camelot Level 8 Level 8 (45,790 points)

    Before you go anywhere you need to define some basic parameters.

     

    For example, what do you want/intend to 'clean up'?

    It sounds like a dumb question, but it isn't.

     

    No script can decide for you what your 'cleaning' should consist of - sure, it can find old files, or big files, or files with specific names, or in specific directories, or owned by specific users, or any number of other parameters, but you're the one that has to define the scope and the limit... HOW old? How big? What names?, etc.

     

    Once you know what your rules are you can look at different implementation options, but as it stands there really isn't much you can do since your target is ill-defined.

     

    Then you need to make sure your data is backed up properly. At some point, one day, ANY 'clean-up' task, whether manual or automated) is going to throw away a file that someone absolutely desperately needs. It's going to happen, and you will need a backup of your data that you can fall back to.

     

    As a final thought, computers perform this task pretty awfully - there's often too much subjectivity in deciding what is worth keeping. Don't be surprised if your cleaning 'process' comes down to you dedicating an hour or two every week/month to take a look at what's there, rather than a headless automated script.

  • 2. Re: Schedule Clearing Files from a drive that is being served
    scoryell Level 1 Level 1 (0 points)

    Sorry great point way too broad, my request is much simpler. I just want to delete files off a volume folder that has a creation date greater than 30 days. So if it has been on the volume more than 30 days it will be deleted.

  • 3. Re: Schedule Clearing Files from a drive that is being served
    Camelot Level 8 Level 8 (45,790 points)

    OK... if that's what you want, it's trivial.

     

    You can do it via AppleScript and the Finder:

     

    tell application "Finder"

              set oldFiles to every file of entire contents of disk "Volume Name" whose creation date is less than ((current date) - 30 * days)

      delete oldFiles

    end tell

     

    but the Finder is notoriously slow in dealing with large numbers of files and folders. If the disk is large (or, more correctly, if there is a large number of items on the disk) you may be better off with a shell command instead:

     

    do shell script "find /Volumes/VolumeName -Btime +30 -delete"

  • 4. Re: Schedule Clearing Files from a drive that is being served
    scoryell Level 1 Level 1 (0 points)

    So if I do this shell script, it will continue todo this until I excute another code to stop or is this code have to be ran everything I need it to work?

  • 5. Re: Schedule Clearing Files from a drive that is being served
    Camelot Level 8 Level 8 (45,790 points)

    So if I do this shell script, it will continue todo this until I excute another code to stop or is this code have to be ran everything I need it to work?

    As written, the shell command will find files, delete them and then go away.

    In the same way the AppleScript version will tell the Finder to find files and delete them, and then go away.

     

    So both approaches will need some kind of schedule behind them if you want them to run automatically. launchd would be the presumed approach since it can launch any task on just about any schedule you like.