CRON Cheatsheet

Posted on 24.10.17   Cheatsheet CRON Linux

I’m tired of always looking up CRON scheduling, so here it is including some examples.

CRON Scheduling table:

 

# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │                                       7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * *  command to execute

 

CRON Examples:

Note that all the cron jobs output are redirected to /tmp/log.txt. If omitted, the default is to send an email to the sysadmin email address (if configured).

Run Python script every night at 02 am

* 02 * * * python /path/to/script.py >> /tmp/log.txt 2>&1

 

Run shell script every 10 minutes

*/10 * * * * /path/to/script.sh >> /tmp/log.txt 2>&1

 

Workaround for running a script every 15 seconds

* * * * * /path/to/script.sh >> /tmp/log.txt 2>&1

* * * * * sleep 15; /path/to/script.sh >> /tmp/log.txt 2>&1

* * * * * sleep 30; /path/to/script.sh >> /tmp/log.txt 2>&1

* * * * * sleep 45; /path/to/script.sh >> /tmp/log.txt 2>&1

 

Run a script every weekday at midnight

0 0 * * 1-5 /path/to/script.sh >> /tmp/log.txt 2>&1

 

Run script every Monday in June, July and August at 0530

30 05 * 6-8 1 /path/to/script.sh >> /tmp/log.txt 2>&1

 

Related post:

Linux Cheatsheet

More on ITDB

Create a cmd alias/shortcut for issuing commands on remote computer


Managing WiFi profiles in Windows 10


How to debug a non starting application with ProcMon


Turn off CTRL + ALT + DEL at login prompt Windows 10


Telnet alternative to check if port is open on host