Linux practical articles - crond task scheduling

1. Schematic diagram of the principle:
2. crond task scheduling
    crontab to set up scheduled tasks.
3. Overview
    Task scheduling: refers to a specific command or program that the system executes at a certain time.
    Task scheduling classification: 1. System work: Some important work must be performed in cycles. such as virus scanning
    2. Individual user work: Individual users may wish to perform certain procedures, such as backups of the mysq| database.
4. Basic grammar
        crontab [options]
    4.1. Common options
-e
 Edit crontab timed tasks
-l
Query crontab tasks
-f
Delete all crontab tasks of the current user
5. Quick Start
    5.1. Task requirements
    Set the task schedule file: /etc/crontab
    Set up a personal schedule. Execute the crontab -e command
    Then enter the task into the schedule file
    Such as: */1****ls -l /etc/>/tmp/to.txt
    It means to execute the ls -l /etc/ >/tmp/to.txt command every minute of every hour
    
    5.2, the steps are as follows
  1. cron -e 
  2.  * / 1 **** ls -l /etc/>/tmp/to.txt
  3. It takes effect after saving and exiting
  4. ls -l /etc/ > /tmp/to.txt is automatically invoked every minute
    
    5.3. Parameter details
     
    
    
6. Several application examples of task scheduling
     Case 1: Append the current date information to the /tmp/mydate file every minute
            1) First write a file mytask1.sh
                    date >> /tmp/mydate
            2) Give mytask1.sh an executable permission
                    chmod 744 /home/mystask1.sh
            3)crontab -e
            4)*/1**** /home/mytask1.sh
            5) Success
     Case 2: Append both the current date and the calendar to the /home/mycal file every minute
            1) First write a file mytask2.sh
                    date >> /tmp/mycal
                    cal >> /tmp/mycal
            2) Give mytask2.sh an executable permission
                    chmod 744 /home/mystask2.sh
            3)crontab -e
            4)*/1**** /home/mytask2.sh
            5) Success
    
     Case 3: Backup the mysql database testdb to the file mydb.bak at 2:00 am every day.
            1) First write a file mytask3.sh
                   /usr/local/mysql/bin/mysqldump -uroot -proot testdab >/tmp.mydb.bak
            2) Give mytask2.sh an executable permission
                    chmod 744 /home/mystask3.sh
            3)crontab -e
            4)0 2 *** /home/mytask3.sh
            5) Success
7. Crontab related commands:
    1) crontab -r: Terminate task scheduling.
    2) crontab -l: List which tasks are currently scheduled.
    3) service crond restart [restart task scheduling]

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=324131723&siteId=291194637