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.
|
|
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.
|
|
Every 5 minutes between 9:00 and 16:00 Monday through Friday, January through May and September through December