Skip to content

Instantly share code, notes, and snippets.

@DevGW
Last active March 13, 2023 15:59
Show Gist options
  • Save DevGW/a19f2e6923133e3f429e7a93d200ebee to your computer and use it in GitHub Desktop.
Save DevGW/a19f2e6923133e3f429e7a93d200ebee to your computer and use it in GitHub Desktop.
Cron Cheatsheet #hha_ank
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

For details see man 4 crontabs

Format

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)

Operators

Operator Description
* all values
, separate individual values
- a range of values
/ divide a value into steps

Examples

Example Description
0 * * * * every hour
*/15 * * * * every 15 mins
0 */2 * * * every 2 hours
0 18 * * 0-6 every week Mon-Sat at 6pm
10 2 * * 6,7 every Sat and Sun on 2:10am
0 0 * * 0 every Sunday midnight
--- ---
@reboot every reboot

Crontab

# Adding tasks easily
echo "@reboot echo hi" | crontab
# Open in editor
crontab -e
# List tasks
crontab -l [-u user]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment