The crontab command is common in Unix and Unix-like operating systems and is used to set instructions to be executed periodically. Stored in the "crontab" file for later reading and execution. The word comes from the Greek chronos (χρνο), which means time. Usually, the instructions stored in crontab are activated by the daemon process. Crond often runs in the background and checks every minute to see if there are scheduled jobs that need to be executed. Such jobs are generally called cron jobs.
There is a scheduled task plan on the windows system. Through step-by-step settings, commands can be executed at a certain time. For example, PHP executes the bat file, and then the bat file executes the php file. But on Linux, you need to use crontab to do scheduled tasks. The execution of the task plan is controlled through a daemon process crond.
Log in to the linux server
Enter crontab -e. After typing, you will automatically enter the vi editor. At this time, you can write commands according to your needs, save and exit after writing.
The saved file is in /var/spool/cron/
The time of Linux scheduled tasks has a fixed format, such as:
This task plan is to execute the test.php file every one minute. You can see that the crontab task plan is generally divided into two parts. The first part is the time, which is defined at what time, and the second part is what to do at this time. .
The PHP language is used here, the content of the test.php file
<span style="font-size: 14px;"><?php<br> file_put_contents('/home/test.php',date('Y-m-d H:i:s',time()),FILE_APPEND);<br></span>
So this task plan is to download to home every one minute Write the time in the test.php file
There are usually five * signs in front of it and 5 times are used to represent
Minute Hour Day Month Week
##Example
You can use online tools to test whether the task plan is written correctlyhttps://tool.lu/crontab/
Execute every one minute Once
<span style="font-size: 14px;">*/1 * * * *<br></span>
Executed once every day at 1.30 am
<span style="font-size: 14px;">30 1 * * *<br></span>
Executes every Monday at 8:00 am
<span style="font-size: 14px;">0 8 * * 1<br></span>
<span style="font-size: 14px;">30 19 * * 1-5<br></span>
<span style="font-size: 14px;">30 11,17 * * 1-5<br></span>
<span style="font-size: 14px;">30 11 * * 1-5<br>40 17 * * 1-5<br></span>
<span style="font-size: 14px;">0 18 */2 * * <br><br></span>
##crontab -e Write task plan
yii2 Configure crontab scheduled tasksWhat is the Linux user control scheduled task Crontab command and detailed explanationExample explains how to use crontab to regularly back up MySQL
The above is the detailed content of Detailed explanation of Linux scheduled task crontab. For more information, please follow other related articles on the PHP Chinese website!