This article uses the crontab command in the Linux environment to set up scheduled periodic execution of tasks. Share with you for your reference, the details are as follows: From the Linux help, the crontab command has the following parameters:
Use scenario 1: Perform some periodic statistical business operations, such as counting the performance of all salesmen and each team on the previous day, the number of people in each team, the amount of tasks, the amount of completion, etc. at 0:00 am every day, and inserting them into the database for easy viewing Use scenario 2: Instead of manually executing some repetitive operations, for example, when my girlfriend was waiting for the announcement of the score line for the postgraduate entrance examination, I wrote a timing program to monitor the news headlines of the postgraduate entrance examination website in real time, and at the same time connect to the SMS verification code platform. As long as the title of the news headline changes, a text message will be sent to the mobile phone. (The following uses crontab command in scenario 2 as an example) The jianting.php code to be executed: <?php $log = "/var/www/html/log.txt"; //Log file (note to set writable permissions) $url = 'http://yz.chsi.com.cn/'; //URL to be monitored $info = file_get_contents($url); //Get the homepage html preg_match('|<h4>(.*?)<\/h4>|i',$info,$m);//Regular match headline content if($m[1] != '<a href="/sytj/tjyx/gosytj.action?entrytype=yzgr" rel="external nofollow" target="_blank">2018 National Master's Admissions Adjustment Intention Collection Service System</a>') { //The title has changed//Judge whether there is a record in the log. If it is empty, record one and send a text message or email notification $str = file_get_contents($log); $str = trim($str); $bom = pack('H*','EFBBBF'); $str = preg_replace("/^$bom/", '', $str); //Remove BOM if($str == ""){ $text = 'Listen for changes'; file_put_contents($log,$text,FILE_APPEND); //Send SMS or email operations... } } Use the which command in Linux to view the PHP installation path: which php To set up a scheduled task, here is a picture stolen from the Internet (crontab format description): crontab -e
An example of writing a command that executes once every 10 seconds: * * * * * /usr/bin/php /var/www/html/jianting.php * * * * * sleep 10; /usr/bin/php /var/www/html/jianting.php * * * * * sleep 20; /usr/bin/php /var/www/html/jianting.php * * * * * sleep 30; /usr/bin/php /var/www/html/jianting.php * * * * * sleep 40; /usr/bin/php /var/www/html/jianting.php * * * * * sleep 50; /usr/bin/php /var/www/html/jianting.php Now check that there is a scheduled task: crontab -l Restart crontab service service crond restart I changed the server and encountered the problem of being unable to execute PHP files. The solution is: 5 0 * * * /usr/bin/curl http://www.xxx.com/jianting.php //Use curl command to access PHP file 5 0 * * * cd /var/www/html && /usr/bin/php /var/www/html/jianting.php I hope this article will help you configure your Linux server. You may also be interested in:
|
<<: The implementation of event binding this in React points to three methods
>>: Solution to the problem that mysql local login cannot use port number to log in
Related articles: Install Docker using yum under ...
1. Check the character set of the default install...
Table of contents background 1. The query conditi...
Phenomenon: Change the div into a circle, ellipse...
What is LNMP: Linux+Nginx+Mysql+(php-fpm,php-mysq...
Environment configuration 1: Install MySQL and ad...
What is CN2 line? CN2 stands for China Telecom Ne...
Problem Description As we all know, the SQL to so...
Installing MySQL 5.7 from TAR.GZ on Mac OS X Comp...
Preface In the past, the company used the 5.7 ser...
Xiaobai learned about Vue, then learned about web...
Table of contents First, let's briefly introd...
For example, to query yesterday's newly regis...
The first one is to use jQuery's ajax to send...
Recently, I need to do a small verification exper...