I have a network share I am hosting on a linux NAS in my house. There are a couple of annoyances with Apple lusers leaving .DS_Store files all over the network share, and messed up permissions on the files people upload to the share. Solution?
Learnt about cron and set up a couple of jobs to run.
Type ‘crontab -l’ to see what is currently set to run. ‘crontab -e’ brings up a vi like editor to edit the cron tasks. For specifics on how cron and crontab work check the manpages.
My share is in ‘/c/everybody’ and this is how I overcame these issues:
* * * * * chown -R nobody.nogroup /c/everybody 0 2 * * * find /c/everybody/ -name *.DS_Store -delete
The first line fixes up any messed up permissions. I am not 100% sure when this runs. Possibly immediately? The second line uses ‘find’ to search for those pesky DS_Store files and delete them all in one neat command.
2 thoughts on “Intro to cron / crontab”
The first one will run every minute of every hour of every day of every week and every month. You probably don’t want to do this on a NAS with a lot of files, once every 15 minutes is probably fine
*/15 * * * *
or once an hour at quarter past the hour
15 * * * *
The second one will run at 2 am every morning
Ah cheers John! I was not sure about the whole crontab timing thing at all really.
Yeah the share is small at the moment, but could get large pretty quickly!
I managed to fix up the permission problem properly (when the files are written in the first place), so I have deleted that line from cron.
I do not use Apple, but I presume it’s OK to occasionally delete those DS_Store files without messing up peoples systems? It would probably be a bit of a prick move to run it constantly though ;-)