DEV Community

Cover image for Cron Job
Mallikarjun H T
Mallikarjun H T

Posted on • Updated on

 

Cron Job

What is cron?

The origin of the name cron is from the Greek word for time.

Hear is an quick example for backing up my system at (01 01) every day.

01 01 * * * /usr/local/bin/rsbu -vbd1 ; /usr/local/bin/rsbu -vbd2

well i presume u dont get most of it. don`t worry i got it covered for you. i will explain each and every step.

First there are 5 places we need to understand those are

  • sec 0 - 59
  • min 0 - 59
  • Hr 0 - 23 in 24 Hr fashion
  • day 0 - 30/31
  • month 1 - 12
  • week 0 - 6 (0 being sunday )


| ............... sec (0 -59)
| | ............. minute (0 - 59)
| | | ........... hour (0 - 23)
| | | | ......... day of month (1 - 31)
| | | | | ....... month (1 - 12)
| | | | | | ..... day of week (0 - 6)
| | | | | |
* * * * * *

Examples

  • every year 1st of jan * * * 1 1 *
  • every hour 0 59 * * * *
  • every day at 12 0 * 12 * * *

Top comments (1)

Collapse
 
thefluxapex profile image
Ian Pride

Just like to add that you can repeat jobs at different intervals other than ever min,hour,day,mon,dow.

For example if you want to run a job every 5 minutes you would write:

*/5 * * * * /path/to/bin/or/script
Enter fullscreen mode Exit fullscreen mode

or every 2 horus:

* */2 * * *  /path/to/bin/or/script
Enter fullscreen mode Exit fullscreen mode

You’ve already scrolled down this far, why not join our community of 900k+ developers all learning together?