crond is a daemon process used under linux to periodically perform certain tasks or wait for certain events to be processed, similar to the scheduled tasks under windows, when the installation of the operating system is complete, this service tool will be installed by default and will automatically start the crond process, the crond process will periodically check every minute if there is a task to be performed, and if there is a task to be performed, the task will be automatically executed. If there is a task to be executed, it will be executed automatically. There is a crontab file in the /etc directory, which is the configuration file for system task scheduling.

The contents of /etc/crontab in the unmodified state are as follows.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |    
# *  *  *  *  * user-name  command to be executed

The first 3 lines are used to configure the environment variables for the crond task to run

  • The first line SHELL variable specifies which shell the system will use
  • The second line, the PATH variable, specifies the path where the system will execute commands.
  • The third line of the MAILTO variable specifies that crond task execution information will be sent to the root user via email (if the value of the MAILTO variable is empty, then no task execution information will be sent to the user)

From line 7 to line 14 is the reference to the crontab settings. The meaning is very clear, the setting reference identifies the range of values.

In each of the above fields, the following special characters can also be used.

  • asterisk (*): represents all possible values, for example, if the month field is an asterisk, it means that the command operation is executed every month after the constraints of other fields are met.
  • comma (,): can specify a list range of values separated by commas, e.g., “1,2,5,7,8,9”
  • Middle bar (-): You can use a middle bar between integers to indicate a range of integers, for example, “2-6” means “2,3,4,5,6”
  • Slash (/): You can use a slash to specify the frequency of the time interval, for example, “0-23/2” means once every two hours. Also the forward slash can be used together with an asterisk, for example */10, if used in the minute field, it means once every ten minutes.

Example.

1
*,*/5 9-16 * 1-5,9-12 1-5 root command

Every 5 minutes between 9:00 and 16:00 Monday through Friday, January through May and September through December