【发布时间】:2018-02-14 15:18:25
【问题描述】:
我的 cronjob 实验需要帮助,但我无法完成我想要的。以下是我做的事情。
- 在
/var/www/html/bob/test/index.php中创建一个php文件 - 将目录和文件的权限设置为可执行(0777)
- 指定一个 cronjob
我的index.php
<?php
$myfile = fopen("testfile.txt", "w");
?>
我对 crontab -e 的各种测试参数不起作用
*/1 * * * * root /usr/bin/php /var/www/html/bob/test/index.php
*/1 * * * * root /var/www/html/bob/test/index.php
*/1 * * * * root php -q /var/www/html/bob/test/index.php
*/1 * * * * root /var/www/html/bob/test/index.php
查看我的一些 /var/log/cron 我没有看到任何错误指示。
Sep 6 15:55:01 localhost CROND[4866]: (root) CMD (root /var/www/html/bob/test/index.php)
Sep 6 15:56:01 localhost CROND[4872]: (root) CMD (root /var/www/html/bob/test/index.php)
Sep 6 15:57:01 localhost CROND[4878]: (root) CMD (root /var/www/html/bob/test/index.php)
最后,当我通过#php /var/www/html/bob/test/index.php 运行我的 php 时,代码执行良好并创建了该文本文件。
【问题讨论】:
-
你检查过php错误日志吗?
-
尝试使用文件 testfile.txt 的绝对路径,例如:$myfile = fopen("/home/xxxx/testfile.txt", "w");