我很无助,很绝望。
创建以下crontab后:
SHELL=/bin/bash
PHAR="/usr/bin/php -f /home/heimathafen/customfiles/scripts/7d2d.phar"
# m h dom mon dow command
*/15 * * * * ${PHAR} maintenance
*/5 * * * * ${PHAR} monitor
#50 3,7,11,15,19,23 * * * ${SDTD} reboot
#0 * * * * ${PHAR} backup
#55 23 * * 6 ${PHAR} creategifts
* * * * * ${PHAR} gameevents 0
* * * * * ( sleep 10; ${PHAR} gameevents 1)
* * * * * ( sleep 20; ${PHAR} gameevents 2)
* * * * * ( sleep 30; ${PHAR} gameevents 3)
* * * * * ( sleep 40; ${PHAR} gameevents 4)
* * * * * ( sleep 50; ${PHAR} gameevents 5)
我发现这些作业都没有执行。当我在CLI中运行命令时:
/usr/bin/php -f /home/homeport/customfiles/scripts/7d2d.phar monitor
一切正常。不管我是在它周围放一个sh -c "..."
还是像这样运行
phar文件权限正确(chmod a+x
)且路径正确。crontab也在用户上下文中(主端口)。
我做错了什么?
*/15 * * *
看起来不像一个有效区间。
假设您想要执行你的命令每15分钟,你也应该指定星期。
Crontab条目结构:
# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of the month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of the week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │ 7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * <command to execute>
这可能有用:https://crontab.guru/
我发现了,我很想抽我自己。在无数次调试之后,我遇到了这一行:
define('SERVER_USERNAME', trim(getenv('USER')));
当然,如果您不使用cron运行它,这将工作得很好,因为$USER
在那里是空的。
我将它替换为:
define('SERVER_USERNAME', trim(exec('whoami')));
,你瞧。一切工作。