Cron Formats - Examples & Reference

Cron Formats - Examples & Reference

Last updated:
Table of Contents

Some example of formats you can use to set the frequency your jobs are called.

You can set these values by calling crontab -e with the user you want the command to run as (for root, do sudo crontab -e)

Every minute

Always remember to provide the full path to the command you want to run.

* * * * * /full/path/to/command

Every 5 minutes

Run given command every 5 minutes

*/5 * * * * /full/path/to/command

Every 30 minutes

Run given command every half-hour

*/30 * * * * /full/path/to/command

Every hour, random minutes

Source: https://unix.stackexchange.com/a/286599/94882

This is useful if you want to run something roughly at the same time but not at exactly the same time every hour

Cron will run at every hour, but will sleep for up to 1 hour1 and then run command.

SHELL=/bin/bash

# sleep for a random period (up to 1 hour) and run command.
0 * * * * sleep $((RANDOM*3600/32768)) && /full/path/to/command

Every day, random hours and minutes

86400 is the number of seconds in 24 hours

As above; command will run once every day, but at random times.

SHELL=/bin/bash

# sleep for a random period (up to 1 day) and then run command.
0 0 * * * sleep $((RANDOM*86400/32768)) && /full/path/to/command

Every hour

0 * * * * /full/path/to/command

Every 12 hours

Will run at 00:00 and 12:00, every day.

0 */12 * * * /full/path/to/command

Every day at specific time

Run the given command every day, at the given time

Every day at 6 AM

0 6 * * * /full/path/to/command

Every day at 8:30 PM

Note that Hours are in 24-hour format, so 20:30

30 20 * * * /full/path/to/command

Every 2 days at 10 PM

0 22 */2 * * /full/path/to/command

1: SO comment: RANDOM returns a randomly-selected integer between 0 and 32767. Multiplying that by 3600 and dividing by 32768 results in an integer between 0 and 3599 (number of seconds in an hour)