Cheat Sheet - cron

Format

Min  Hour Day  Mon  Weekday
*    *    *    *    *  command to be executed
┬    ┬    ┬    ┬    ┬
│    │    │    │    └─  Weekday  (0=Sun .. 6=Sat)
│    │    │    └──────  Month    (1..12)
│    │    └───────────  Day      (1..31)
│    └────────────────  Hour     (0..23)
└─────────────────────  Minute   (0..59)

Examples

Expression Meaning
0 * * * * every hour
*/15 * * * * every 15 mins
0 */2 * * * every 2 hours
0 0 * * 0 every Sunday midnight
@reboot every reboot

Crontab

Check crontab of a user (default=root) user:

sudo crontab -l [-u user]

Edit the crontab of the root user:

sudo crontab -e

Import new crontab:

crontab /etc/cron.d/mongodb-consistent-backup

If the cron execution is logged via syslog:

sudo less +G /var/log/cron

Or systemd journal:

sudo journalctl _COMM=cron

# or

journalctl _COMM=cron --since="date" --until="date"

cron @reboot run as startup

Tools:

  • https://crontab-generator.org/