Create a scheduled task using crontab in CentOS
In Linux, you can use crontab to create a scheduled task.
Common integrations
Crontab-e: edit a task
Crontab-l view all tasks [this user]
Crontab-r cancels all tasks [this user]
Task format
××××× + Command (specific task)
The first five parameters indicate the time, which is:
Parameter range
Minute 0-59
Hour 0-23
Date 1-31
Month 1-12
Week 0-6 (0 represents Sunday)
Special symbols
To accurately represent timing, special symbols are required to describe the specific task execution time. There are several symbols:
"/" Indicates the interval of each and every second.
"*" Indicates any time
"-" Indicates a period of time from one time point to another.
"," Indicates the discrete time.
Case
0 8 1 1 0 command executed at every year on January 1, January 1
*/30 * the command is executed every 30 minutes.
0 6-18 *** command: Execute command from to every day
At, and every day, the command is executed
0 6-18/3 ***/user/bin/PHP/var/www/html/save. php is executed every three hours from to every day using/user/bin/php/var/www/html/save. php
Note:
The commands set in crontab are relative paths, so the scripts executed in the command should be set to absolute paths as much as possible. On the other hand, if there is output in the script, it will be output to the current user directory. Therefore, if there is a path in the script, set it to an absolute path!
Crontab errors will be sent to the user by email. The directory in centos is/var/spool/mail/user. long-term accumulation may result in excessive space occupation in/var/and should be cleared in time. (DG in vi)