Linux——(Chapter 8) Scheduled Task Scheduling

Table of contents

1 Overview

2.crontab service management

3.crontab scheduled task settings


1 Overview

Task scheduling : refers to specific commands or programs executed by the system at a certain time

Task scheduling classification :

        (1) System work: Some important work must be performed repeatedly. Such as virus scanning.

        (2) Individual user work: Individual users may want to execute certain programs. Such as backing up the database.

2.crontab service management

Restart the crond service

# systemctl restart crond

3.crontab scheduled task settings

crond   [options]

Options Function
-e Edit crontab
-l Query crontab tasks
-r Delete all crontab tasks for the current user

(1) crontab -e   , enter the editing interface. This will open vim to edit your work

***** Tasks performed

Parameter Description

project  meaning scope
First" * " The minute of the hour 0-59
the second" * " What hour of the day 0-23
The third" * " Day of the month 1-31
the fourth" * " Which month of the year 1-12
the fifth" * " day of the week 0-7 (0 and 7 both represent Sunday)

(2) Special symbols

special symbols

special symbols meaning
* Represents any time. For example, the first "*" means execution every minute for an hour.
, Represents discontinuous time. For example, the "0 8,12,16 * * *" command means that the command will be executed at 8:00, 12:00, and 16:00 every day.
- Represents a continuous time range. For example, the "0 5 * * 1-6" command means executing the command at 5:00 a.m. from Monday to Saturday.

*/n

Represents how often it is executed. For example, the " */n * * * * " command means executing the command every 10 minutes.

(3) Execute commands at a specific time

Execute command at specific time

time meaning
45 22 * ​​* * Command Execute the command at 22:45 every day
0 17 * * 1 command Execute the command every Monday at 17:00
0 5 1,15 * * Command Execute the command at 5:00 am on the 1st and 15th of every month
40 4 * * 1-5 commands Execute the command every Monday to Friday at 4:40 a.m.
*/10 4 * * * Command Execute the command every 10 minutes at 4 am every day
0 0 1,15 * 1 command

The command will be executed on the 1st and 15th of every month, and at 0:00 every 1st.

Note : It is best not to appear the day of the week and the number at the same time, because they both define days. Very easy to confuse administrators.

for example:

        Every minute, append the file list under /home to the /temp/a.txt file

        */1 * * * *  ls  -l   /etc  >>  /temp/a.txt 

Guess you like

Origin blog.csdn.net/m0_45447650/article/details/131982573