Cleaning up all the screenshots

Im using Scrup in conjunction with its nifty little partner recv, a hungry hungry php script, to automatically upload screenshots from my macbook to my home server. A setup like this is super neat when discussing any screen related things, especially over the phone. Fact is I find it so useful that I started thinking about eventually cleaning up all the uploaded screenshots..

A task perfectly fitted for our long time UNIX friend find and his cousin cronCron is a time-based job scheduler and find.. finds files.

What I want is to delete all uploaded screenshots on a nightly basis. Each uploaded file is stored in a directory of its own. Im using an apache2 webserver to host the files thus all files are owned by user www-data. I want this nightly cleaning mission to be run by this user. www-data is not allowed to log in herself why we will have to add the cleaning job to her crontab as a normal user. The command below will open up www-data’s crontab in your favourite editor (vi).

sudo crontab -u www-data -e

To run the cleaning job at midnight, enter the row below, but replace /path/to/www-server/and/uploads with the actual path to your web servers doc root and uploads directory.

0 0 * * * find /path/to/www-server/and/uploads/* -prune -type d -print0 -exec rm -rf {} \;

Save and exit the file.

Rejoice!

About jens

handsome
This entry was posted in Mac OS X, code, linux. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>