About Crontab
Cron is a time based job scheduler in Unix like system and the scheduled job is called cron job.
The action of a cron is driven by a crontab file, which stores the list of scripts or commands to execute and instruction on when to execute each of them.
- To view the crontab file for the connected user: crontab -l
- To edit the crontab file for the connected user: crontab -e
(** 'crontab -e' It will open the crontab in a vi editor and you can edit/save the crontab as you do for any other file in a vi editor.
Below screenshot explains, how the scripts are scheduled in a crontab:
There are 5 fields to control the scheduling of the job. If any of the field contains '*', then the job is executed every occurances of that time. Example, if '*' is mentioned for 'Hour', then the job is executed every hour, provided that all other 4 fields conditions match.
Few Examples:
15 * * * * <script to execute> : The job will execute 15 mins of every hour for every day.
0 6 * * * <script to execute> : The job will execute everyday at 6:00 AM.
0 0 1 * * <script to execute> : The job will execute at midnight on 1st of every month.
0 21 * * 0 <script to execute> : The job will execute at 9:00 PM every Sunday.
0 21 * * 0,1,2 <script to execute> : The job will execute at 9:00 PM every Sunday, Monday & Tuesday.
30 0,6,12,18 * * 6 <script to execute> : The job will execute every six hour (00:30, 6:30 AM, 12:30 PM & 6:30 PM) every Saturday.
*/10 9 * * * <script to execute> : The job will execute every 10 mins from 9 AM to 10 AM evryday.
0 0 1 1 * <script to execute> : The job will execute at midnight on January 1st of every year (Once a year).
