The article directories

  • Crond task scheduling
    • 1. An overview of the
    • 2. Basic grammar
    • 3. Quick start
    • 4. Application examples
    • 6. Crond related directives

Crond task scheduling

  • Crontab Configures scheduled tasks

1. An overview of the

  • Task scheduling: refers to a specific command or program executed by the system at a certain time.
  • Task scheduling classification: 1. System work: Some important work must be performed over and over again. Such as virus scanning
  • Individual user work: Individual users may want to perform certain programs, such as backups of the mysql database.
  • Schematic diagram

2. Basic grammar

Crontab [option]Copy the code
  • Commonly used options

3. Quick start

  • Set the task scheduling file:/etc/crontab
  • Set up individual task scheduling. performcrontab -eCommand.
  • Then enter the task into the schedule file
  • Such as:
* /1 * * * * ls"L/etc / > / TMP/to. TXTCopy the code

Run ls -l /etc/> / TMP /to. TXT every minute of every hour

Parameter Details

  • Description of 5 placeholders

  • Description of special symbols

  • Special time execution cases

4. Application examples

  1. Case 1: Every 1 minute, change the currentDate information, appended to the/tmp/mydateIn the file
* /1 * * * * date >> /tmp/mydate
Copy the code
  1. Case 2: Every 1 minute, turn the currentThe date ofandThe calendarIs appended to the/home/mycalIn the file

    Steps:

    (1) vim /home/my.shWrite contentdate >> /home/mycalcal >> /home/mycal

    (2)my.shAdd execution permission,chmod u+x /home/my.sh

    (3) crontab -eincrease*/1 * * * * /home/my
  2. Case 3: Every morningAt 2:00Mysql databasetestdb, back up to a file.

    Tip: the instruction isMysqldump -u root -p password database > /home/db.bak

    Steps:

    (1) crontab -e

    (2)
0 2 * * * mysqldump -uroot -proot testdb > /home/db.bak
Copy the code

6. Crond related directives

  • Conrtab -r: terminates task scheduling.
  • Crontab -l: lists the current scheduling tasks
  • Service crond restart