On planning tasks under linux

On planning tasks under linux

Friends, when you are doing program development, have you ever bothered to realize a mall website or a small program to automatically execute a certain method?

Today, Si Meng php brings you this solution. Of course, there are many ways to achieve this. Today, the editor will explain to you that the configuration of crontab under Linux is to be set! Okay, let’s teach you an introduction to this operation!

First of all, I want to explain to you that the editor will explain to you the implementation of this operation under Linux. As for Windows, I can explain it to you later!

(1) We need to use the yum install -y vixie-cron command to install the scheduled task service, friends can use crontab -e to check before the installation, whether the server has this service installed!

(2) After installation, we can use crontab -e to add our scheduled tasks. I will write some small examples for you:

 */1 * * * */usr/bin/curl -o temp.txt http://www.baidu.com/index.php/Api/Contab/offeredCoupon
 Execute the offeredCoupon method under the following Api group every minute
 30 21 * * */usr/bin/curl -o temp.txt http://www.baidu.com/index.php/Api/Contab/offeredCoupon
 The above example means that the offeredCoupon method under the following Api group is executed at 21:30 every night
 45 4 1,10,22 * */usr/bin/curl -o temp.txt http://www.baidu.com/index.php/Api/Contab/offeredCoupon
 The above example means that the offeredCoupon method under the following Api group is executed at 4:45 on the 1, 10, and 22 of each month
 10 1 * * 6,0/usr/bin/curl -o temp.txt http://www.baidu.com/index.php/Api/Contab/offeredCoupon
 The above example means that the offeredCoupon method under the following Api group is executed every Saturday and Sunday at 1:10

Note (the following is an explanation of the above):

  * * * * * command 
  Time-sharing day, month and week order 
 The first column indicates the minutes 1~59, and each minute is represented by * or */1 
 The second column indicates hours 1 to 23 (0 indicates 0 o'clock) 
 The third column indicates dates 1~31 
 The fourth column represents the month from 1 to 12 
 The fifth column identification number week 0~6 (0 means Sunday) 
 Command to be run in column 6 
          (3) After editing the file, press the ESC key, then (:wq) save and exit
          (4) service crond restart restart the scheduled task
Reference: https://cloud.tencent.com/developer/article/1056008 On planning tasks under Linux-Cloud + Community-Tencent Cloud