【发布时间】:2017-07-07 04:14:39
【问题描述】:
我想在我的 Raspberry 中添加一个 cron 作业,以每五分钟执行一次任务。 所以我在终端做:
crontab -e
然后在文件中添加:
*/1 * * * * /usr/bin/php myscript path.
脚本非常简单。只是试试它是否有效:
<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = date("l jS \of F Y h:i:s A") . "<br>";;
fwrite($myfile, $txt);
fclose($myfile);
?>
问题是日期没有更新,所以 cron 作业不起作用。知道这个问题吗?
更新
这是我得到的,当我执行 crobtab -e 时
GNU nano 2.2.6 File: /tmp/crontab.3IXg0z/crontab
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
* * * * * /usr/bin/php /full/path/myscript.php
【问题讨论】:
-
你确定它不起作用吗?检查您帐户的邮件。 cron 将输出/作业日志通过电子邮件发送到 account.plus
.../php myscript path意味着您的 php 代码文件称为myscript,并且您将path作为命令行参数传递。 -
您能否在crontab tag wiki 上完成调试步骤并报告您的发现?
-
脚本有777权限,作为文件。我添加的完整行是: */5 * * * * /usr/bin/php /var/www/mydomain.com/public_html/test.php
标签: php linux cron raspberry-pi