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
Judging from the results, there is no fixed patte...
Detailed explanation of Java calling ffmpeg to co...
Table of contents 1. Basic types 2. Object Type 2...
This article shares the specific code of JavaScri...
:is dynamic component Use v-bind:is="compone...
Table of contents 1. Preparation 2. Writing comma...
Drop-down menus are also very common in real life...
Table of contents 1. List traversal 2. The role o...
By default, the MyISAM table will generate three ...
Installation suggestion : Try not to use .exe for...
The project was tested these days, and the tester...
Without further ado, here are the renderings. The...
Table of contents 1. Concept 1.1 Definition 1.2 D...
On the server, in order to quickly log in to the ...
1: Baidu website login entrance Website: http://ww...