Detailed explanation of crond timing tasks

First, let's take a look at the chkconfig command:

The chkconfig command checks and sets various services of the system. This is a program developed by Red Hat in accordance with the GPL rules. It can query which system services the operating system will execute in each execution level, including various resident services. Keep in mind that chkconfig does not automatically disable or activate a service immediately, it simply changes the symlink.

  parameter:

     --add: Add the specified system service, let the chkconfig command manage it, and at the same time add relevant data to the system startup description file;

     --del: Delete the specified system service, which is no longer managed by the chkconfig command, and delete related data in the system startup narrative file at the same time;

       --level<level code>: Specify which execution level the read system service should be enabled or disabled in .

List of grade codes:

Level 0 means: means shutdown
Level 1 means: single-user mode
Level 2 means: multi-user command line mode without network connection
Level 3 means: multi-user command line mode with network connection
Level 4 means: not available
Level 5 means: multi-user mode with graphical interface
Level 6 means: reboot

chkconfig --list #List all system services.
 
 

[root@learning ~]# chkconfig --list crond
crond 0:off 1:off 2:on 3:on 4:on 5:on 6:off

List whether the system has executed crond services at each execution level

 

There are two types of linux scheduled tasks:

1. Tasks executed by the system itself regularly (system task scheduling)

For example, polling the system log, backing up system data, clearing the system cache, etc., you can configure the file /etc/crontab through vi. It is a plain text file. Of course, only root can configure it. After modification, you need to pass /etc/init. d/crondrestart restarts the crond service

[root@learning ~]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# 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,f                                                                                        ri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed

2. Scheduled tasks performed by users (user scheduling tasks)

  1) at: It is only suitable for sudden scheduling tasks that are only executed once and ends, depending on the service ------atd

  2) anacron: It is suitable for servers that are not powered on 7*24 hours. It is a scheduling task to be executed at boot. After booting, it will automatically detect the tasks that should be executed but not executed during the shutdown period, and execute it once after booting.

  3) crond: a daemon process (that is, a process executed in the background), which depends on the service ------crond. By default, it checks whether there are scheduled tasks to be executed in the system every minute. Good rules perform this task, so for second-level timing tasks, crond itself cannot be implemented, and must be improved through methods...
    The difference between crond and crontab: crond service is a running program, and crontab is a user-use The command to set timing rules is an executable file------/usr/bin/crontab

    Syntax of crondtab:

        parameter:  

          -u: Specify the user under which to edit the scheduled task. By default, it is not written as the current user.

          -e: Modify the scheduled task, that is, the content of the ceontab file

          -l: View timed tasks, that is, the content of the ceontab file

          -r: Remove the scheduled task, delete the entire crontab file of the current user, generally not used, but directly -e, take the file and delete the unnecessary content

          -i: confirm function

          crontab -l/-e operates on the current user's crontab file in /var/spool/cron, that is

                                                crontab -u root -l/-e == cat/vi /var/spool/cron/root

          When a user creates a scheduled task, the corresponding configuration file will exist in /var/spool/cron/, and the file name is the same as the user name

 

    The user's timed task rules are generally divided into 6 columns:

      1.minute【0~59]  hour【0~23】  day【1~31】  month【1~12】  week【0~7】  command

      2. Both 0 and 7 in week are Sundays, you can also use sun, mon, tue, wed, thu, fri, sat instead

      3. Try not to use day and week together

      4. Symbol:

* Indicates any time (00 23 * * * cmd: execute cmd at 23:00 every day)
- time limit
range of split periods
/n

Every n time units, usually add * (*/5 * * * * cmd : execute cmd every five minutes)

 

 

 

 

 

 

 

 

Extension:

1. We can control whether users in the file are allowed or not allowed to use the crontab command by editing the two files /etc/cron.deny and /etc/cron.allow. The priority of /etc/cron.allow is relatively high, generally used /etc/cron.deny, just write users who are not allowed to use the crontab command

2. The configuration files of all users are stored in the /var/spool/cron/ directory by default, and the file name is named after the user name

 

Guess you like

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