Cron-Job不执行PHP PHAR

发布于 2025-02-13 03:28:59 字数 882 浏览 0 评论 0原文

我完全无助,绝望。

创建以下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也在UserContext(HomePort)中。

我在做什么错?

I am totally helpless and sheer despair.

After I created the following 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)

I found that none of these jobs are executed.
When I run the command on the CLI:

/usr/bin/php -f /home/homeport/customfiles/scripts/7d2d.phar monitor

everything works fine. No matter if I put an sh -c "..." around it or just run it like that.

The phar file has the right permissions ( chmod a+x ) and the path is correct.
Also the crontab is in the usercontext (homeport).

What am I doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

極樂鬼 2025-02-20 03:29:00

*/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/

*/15 * * * doesn't look like a valid interval.

Assuming that you want to execute your command at every 15th minute, you should also specify the day of the week.

Crontab entry structure:

# ┌───────────── 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>

This might be useful: https://crontab.guru/

你是我的挚爱i 2025-02-20 03:29:00

我找到了它,很想鞭打自己。
在无数的调试之后,我遇到了这一行:

define('SERVER_USERNAME', trim(getenv('USER')));

当然,如果您不用Cron运行它,则可以很好地工作,因为$ user在那里空了。

我替换为:

define('SERVER_USERNAME', trim(exec('whoami')));

lo and to。一切都起作用。

I found it and would love to whip myself.
After countless debugs I came across this line:

define('SERVER_USERNAME', trim(getenv('USER')));

Of course, this works beautifully if you don't run it with cron, because $USER is empty there.

I replaced it with:

define('SERVER_USERNAME', trim(exec('whoami')));

and lo and behold. Everything works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文