Operation of timed task under Linux

##############################

Task scheduling under Linux is divided into two categories, system task scheduling and user task scheduling. 
1. System task scheduling: tasks that the system needs to perform periodically, such as writing cached data to the hard disk, log cleaning, etc. 
    In the / etc / crontab file, this is the configuration file for system task scheduling. 
2. Scheduling of user tasks: tasks that users regularly perform, such as user data backup and regular email reminders. 
    Users can use the crontab tool to customize their scheduled tasks. 
    The crontab files are saved in the / var / spool / cron directory. The file name is the same as the user name

 

##########################

1. System scheduled tasks: such as clearing system logs and clearing system caches-> not much attention 
    The path to query system timing processing tasks: 
        path 1: 
            cd /etc/logrotate.d/-> can write scheduled tasks 
            less syslog 
        path 2: 
            cat / etc / crontab-> Not recommended, but you can see the format 
        Path 3: 
             ls / etc / | grep cron * 
                 anacrontab 
                 cron.d-                  > Same path 2, you can write a scheduled task   
                 cron.daily 
                 cron.deny               -> Control common users to use scheduled tasks crontab 
                 cron.hourly 
                 cron.monthly 
                 crontab
                 cron.weekly
 2. The user's scheduled tasks- > focus on

 

##################################

The first four lines are used to configure the environment variables for running the crond task. The 
first line SHELL variable specifies which shell the system will use. Here is bash. The 
second line PATH variable specifies the path of the system execution command. The 
third line MAILTO variable specifies crond. The task execution information will be sent to the root user by email. 
If the value of the MAILTO variable is empty, it means that the task execution information is not sent to the user 
. The HOME variable on the fourth line specifies the home directory used when executing commands or scripts. 

Asterisk ( * ): represents all possible values. 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 (,): You can specify a list range with comma-separated values, for example, " 1,2,5,7,8,9 " 
middle bar ( -): You can use the middle bar between integers to represent an integer range , For example, "2-6" means "2,3,4,5,6 " 
forward slash ( /): You can use a forward slash to specify the interval frequency of time, for example "0-23 / 2 " means every two hours once.


Summary: It is best to use 2 for Arabic numerals. Week and day are best not to be used at the same time. Timed tasks need to be commented. You can direct to log files or empty files. Timed tasks must be absolute paths, and the directory must exist to produce the result crontab service Must be up and running

 

############################

SH * 0 * * 0 / the root / AutoTest / hwtest / Auto- del - log.sh 
0 * / * * * to python3. 3 / the root / AutoTest / hwtest / hwtestpro / BBS / srun_bbs_test.py 
0 * / * * *. 1 to python3 /root/autotest/hwtest/hwtestpro/bbs/url_main.py executed at 

zero and zero,
every 3 hours and 0 minutes,
every 1 hour and 0 minutes,

 

####################################

Time format is as follows: 
f1 F2 F3 F4 F5 Program 
explained:
f1 is a minute, minute ( 0 - 59 )
F2 for hours, hours ( 0 - 23 )
F3 represents a month in the first few days, the first day of the month ( 1 - 31 )
F4 indicate the month, the month (1 - 12)
F5 represents the day of the week. Day of the week (0-7) (Sunday is 0)
program indicates the program to be executed.
When f1 is *, it means to execute the program every minute, when f2 is *, it means to execute the program every hour, and so on. When f1 is ab, it means to execute from the a minute to the b minute, f2 When it is ab, it means that it must be executed from the a to the bth hour, and the rest by analogy. When f1 is * / n, it means that it is executed every n minutes. When f2 is * / n, it means that it is executed every n hours. By analogy, when f1 is a, b, c, ..., it means the a, b, c, ... minutes to be executed, and f2 is a, b, c, ... it means the a, b, c, ... ... hours to execute, and so on


 

######################

crontab- l means to list all scheduled tasks. 
crontab -r means to delete user's scheduled tasks. After executing this command, all users' scheduled tasks will be deleted. After executing crontab -l, the user will be prompted: "no crontab for admin ” 
Crontab -e means to edit the scheduled task,

 

###################################

Display of commonly used commands 
Install crontab: yum install crontabs 
crontab service operation instructions:
 / sbin / service crond start // start service
 / sbin / service crond stop // stop service
 / sbin / service crond restart // restart service
 / sbin / service crond reload // Reload configuration 
Check crontab service status:
service crond status

 

##########################################

 

 

 

 

 

 

####################################

         -e      (edit user's crontab )
         -l      (list user's crontab )
         -r      (delete user's crontab )

Guess you like

Origin www.cnblogs.com/andy0816/p/12728882.html