Cronjob configuration syntax
Cron jobs are scheduled tasks that the system runs at predefined times or intervals. Typically, a cron job contains a series of simple tasks that the system runs from a script file.
This article explains the syncatx details and some neat configuration techniques.
The syntax of cronjob in linux is as below.
# Minute Hour Day of Month Month Day of Week Command
# (0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)
Here we can use special words to make the syntax more simple.
@reboot Run once, at startup
@yearly Run once a year "0 0 1 1 *"
@annually (same as @yearly)
@monthly Run once a month "0 0 1 * *"
@weekly Run once a week "0 0 * * 0"
@daily Run once a day "0 0 * * *"
@midnight (same as @daily)
@hourly Run once an hour "0 * * * *"
If you use the first (minute) field, you can also put in a keyword instead of a number and leave the rest of the fields empty.
For example,
@daily /bin/execute/this/script.sh
If we need to run a script in every 10 minutes we can configure the cronjob as,
0,10,20,30,40,50 * * * * /bin/execute/this/script.sh
But we can use the below syntax too as it more simpler than earlier.
*/10 * * * * /bin/execute/this/script.sh