In normal work, you often encounter some routine tasks that need to be run regularly on a daily basis. To solve this problem, you can use the crontab command. Let's take a look at it later ~
First, start the crontab service.
Service crond start # Start the service
Service crond stop # disable the service
Service crond restart # restart the service
Service crond reload # reload Configuration
Then, use crontab-e to edit the routine task, save the task, and exit.
The specific format is described as follows:
The format of each line is: hour, day, month, week
The 1st column indicates minute 1 ~ 59. Each minute is represented by * or */1.
The first column indicates the hour 1 ~ 23 (0 indicates 0 points)
The 3rd column indicates the date 1 ~ 31
The 4th column indicates the month 1 ~ 12
The Identification Number of column 5th is from day of the week to day ~ 6 (0 indicates Sunday)
6th columns of commands to run
It is worth noting that in crontabWhether the command or file path must be fully writtenOtherwise, it is not recognized.
For example, to execute a/home/run/test. Sh script at every day, you can configure it as follows:
0 6 ***/sbin/SH/home/run/test. Sh
Or
0 6 * CD/home/run &/bin/sh test. Sh
Note that the command in the test. Sh script also needs to use the full path; otherwise, crontab cannot be found.
If you want to have other requirements, such as retaining the output, you can redirect the output, which is no different from running a Normal script.
0 6 * CD/home/run &/bin/sh test. Sh> log