Cron is the periodic scheduler in unix systems that allows you to run specific jobs at specific times. You can’t call yourself a unix admin unless you know cron, but it’s one of those bits of knowledge that most of us don’t recall learning. So here is a quick review. Every user has a file called a crontab (caveat, not every user can use cron. They have to exist in the cron.allow file, but that’s for another article. For now, assume that cron is universal and granted to all users) that lists what time a job will run and what that job should be. The format looks like this
$1 $2 $3 $4 $5 $JOB
$1 is minutes of the hour, 00-50
$2 is hour of the day, 00-23
$3 is day of the month, 01-31
$4 is month of the year, 01-12
$5 is day of the week where 0 is Sunday and 6 is Saturday
$JOB is the job that you want to run.
Here is an example
15 00 * * * sync
This job will run the sync command at 15 minutes past midnight every single day. Here’s another
00,15,30,45 * * * * sync
Again with the sync command, but this time the job will be run every 15 minutes every day.
Some versions of cron let you do neat things like this
/15 * * * * sync
This is the exact same as the previous entry, running sync every 15 minutes, but we’re using the / or step marker to indicate that we want things run on multiples of 15 for this field instead of witting each interval out. Not all versions of cron support the step character though, so be sure to test that out before you depend on it. Here’s an example straight from my crontab
15 23 * * 0 rsync -auv jason@galactica.cyborgworkshop.org .
That little guy runs full rsync backups every Sunday night at 23:15 on galactica, my mythtv server.