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. perform
crontab -e
Command. - 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
- Case 1: Every 1 minute, change the currentDate information, appended to the
/tmp/mydate
In the file
* /1 * * * * date >> /tmp/mydate
Copy the code
- Case 2: Every 1 minute, turn the currentThe date ofandThe calendarIs appended to the
/home/mycal
In the file
Steps:
(1)vim /home/my.sh
Write contentdate >> /home/mycal
和cal >> /home/mycal
(2)my.sh
Add execution permission,chmod u+x /home/my.sh
(3)crontab -e
increase*/1 * * * * /home/my
- Case 3: Every morning
At 2:00
Mysql 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