linux crontab

Task scheduling under Linux is divided into two categories, system task scheduling and user task scheduling.

System task scheduling: The work that the system needs to perform periodically, such as writing cached data to the hard disk, log cleaning, etc. There is a crontab file in the /etc directory, which is the configuration file for system task scheduling.

/etc/cron.deny Users listed in this file are not allowed to use crontab commands

/etc/cron.allow Users listed in this file are allowed to use crontab commands

 

User task scheduling: The tasks that users need to perform on a regular basis, such as user data backup, regular email reminders, etc. Users can use the crontab tool to customize their own scheduled tasks. All user-defined crontab files are stored in the /var/spool/cron directory. Its file name is the same as the user name.

/var/spool/cron/ The directory where all user crontab files are stored, named after the user name

 

Meaning of crontab file:

In the crontab file created by the user, each line represents a task, and each field in each line represents a setting. Its format is divided into six fields. The first five paragraphs are time setting paragraphs, and the sixth paragraph is The command segment to be executed, in the following format:

minute hour day month week command

in:

minute: Indicates the minute, which can be any integer from 0 to 59.

hour: Indicates the hour, which can be any integer from 0 to 23.

day: Indicates the date, which can be any integer from 1 to 31.

month: Indicates the month, which can be any integer from 1 to 12.

week: Indicates the day of the week, which can be any integer from 0 to 7, where 0 or 7 represents Sunday.

command: The command to be executed, which can be a system command or a script file written by yourself.

 

In each of the above fields, the following 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 will be executed every month after the constraints of other fields are met.

Comma (,): A list range can be specified with comma-separated values, for example, "1,2,5,7,8,9"

Middle bar (-): You can use a middle bar between integers to represent a range of integers, for example "2-6" means "2,3,4,5,6"

正斜线(/):可以用正斜线指定时间的间隔频率,例如"0-23/2"表示每两小时执行一次。同时正斜线可以和星号一起使用,例如*/10,如果用在minute字段,表示每十分钟执行一次。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326269421&siteId=291194637