Lets learn "Cron job schedule notation"
In this tutorial, we'll learn about the notation that cron jobs use to describe the period in which the job needs to be run.
Notation
You must have seen the cron jobs scheduled defined like
"*/2 * * * *"
Let's learn what this means. The general meaning of each field in the cron job schedule is as follows.
Examples
Let's go through some examples.
45 23 * * 6 /home/user/test.sh
The above example means that the test.sh script should run at 23:45 ( or 11:45 PM ) of every Saturday.
*/2 * * * * /home/user/test.sh
NOTE: we can specify */n to run the program every nth interval of the time. Like in the above example, the script will run in every 2 minutes.
*/2 1,2,3 * * * /home/user/test.sh
Some predefined schedule definitions:
Entry | Description | Equivalent to |
---|---|---|
@yearly (or @annually) | Run once a year at midnight of 1 January | 0 0 1 1 * |
@monthly | Run once a month at midnight of the first day of the month | 0 0 1 * * |
@weekly | Run once a week at midnight on Sunday morning | 0 0 * * 0 |
@daily (or @midnight) | Run once a day at midnight | 0 0 * * * |
@hourly | Run once an hour at the beginning of the hour | 0 * * * * |
@reboot | Run at startup | N/A |
Cron Permissions
There are two files containing cron related permissions:
- /etc/cron.allow: If this file exists, It must contain the user's name for that user to be allowed to use cron jobs.
- /etc/cron.deny: If cron.allow file doesn't exist but cron.deny file exists then, to use cron jobs, users must not be listed in the /etc/cron.deny file.
HOPE YOU LEARNT SOMETHING NEW IN THIS TUTORIAL. FEEL FREE TO COMMENT BELOW IF YOU HAVE ANY DOUBTS. AND STAY TUNED FOR MORE TUTORIALS :)
Comments
Post a Comment