----来源
#!/usr/bin/php -q
<?php
set_time_limit(0);
$domain = filter_input(INPUT_POST, 'domain', FILTER_SANITIZE_URL);
$terms = filter_input(INPUT_POST, 'terms', FILTER_SANITIZE_STRING);
require_once('/home/myaccount/www/scrap/goutte-v2.0.4.phar');
include_once('/home/myaccount/www/scrap/common.php');
$command = "ps -ef|grep data_scrap.php";
$commandResult = shell_exec($command);
$commandResultArray = explode("\n", $commandResult);
if(sizeof($commandResultArray) == 6) {
echo "[".date("Y-m-d H:i:s")."] working...".PHP_EOL;
var_dump($commandResultArray);
exit;
} else {
echo "[".date("Y-m-d H:i:s")."] not working...".PHP_EOL;
}
.
. php scrpt
.
---- Crontab Schedule
*/1 * * * * root /usr/bin/php /cron_script/data_scrap.php >> /cron_script/data_scrap_log.txt
---- Crontab Log(syslog)
Jan 7 12:10:01 dev CRON[2051]: (root) CMD (root /usr/bin/php /cron_script/data_scrap.php >> /cron_script/data_scrap_log.txt)
Jan 7 12:10:01 dev postfix/pickup[643]: 6D6B113A1191: uid=0 from=<root>
Jan 7 12:10:01 dev postfix/cleanup[2018]: 6D6B113A1191: message-id=<20160107031001.6D6B113A1191@mydomain>
Jan 7 12:10:01 dev postfix/qmgr[14721]: 6D6B113A1191: from=<root@mail.mydomain>, size=623, nrcpt=1 (queue active)
Jan 7 12:10:01 dev postfix/local[2021]: 6D6B113A1191: to=<root@mail.mydomain>, orig_to=<root>, relay=local, delay=0.31, delays=0.28/0/0/0.03, dsn=2.0.0, status=sent (delivered to maildir)
Jan 7 12:10:01 dev postfix/qmgr[14721]: 6D6B113A1191: removed
---- cat /cron_script/data_scrap_log.txt
null
----文件权限
chown myaccount:myaccount data_scrap.php
chmod 777 data_scrap.php
chmod +x data_scrap.php
为什么不工作crontab?
php /cron_script/data_scrap.php - &gt;它会运行。
请你的帮助。
答案 0 :(得分:0)
按如下所示更改*/1 * * * * /cron_script/data_scrap.php >> /cron_script/data_scrap_log.txt 2>&1
条目
root
删除php
以及php
二进制文件的路径,因为shebang
文件包含{{1}}