How To Set A Cron Job

Sometimes you need your Raspberry Pi (or other computer) to run a repetitive task. Maybe you want it to take a picture every five minutes, or recite a protection spell every Friday the 13th. To do this, we can use a cron job, or a scheduled task.

To add a cron job, type nano crontab -e into the terminal. A job is formatted as such:

minute hour day month day-of-week command-line-to-execute

You must use this order, and you may not have any missing fields. The acceptable values for each field is as follows:

Field Range of Values
minute 0-59
hour 0-23
day 1-31
month 1-12
day-of-week 0-7 (note that 0 & 7 is Sun, 1 = Mon, 2 = Tue, etc)
command-line-to-execute the command to run along with any parameters you may use

You may also use *, a wildcard character for any given category. This indicates every possible value for the field. So, if you wanted to run a command every day at 1:20pm, your time portion would look like this:

20 13 * * *

Note that we’re using “13” instead of “1” for the hour slot, because we’re using a 24-hour clock. If you wanted to run something every five minutes, you would simply do:

*/5 * * * *

Using the slash, we can divide the wildcard symbol by any number, causing the job to run whenever it’s evenly divisible. And if you’d like to run a script every Friday the 13th at 11:11am and 11:11pm (usually lucky times, even on a very unlucky day), you’d simply write:

11 11,22 13 * 5

Note the hour field–we can select a set of specific times by separating different values with a comma (with no spaces)!

About maddy

i like critical computing! @mlvarner