【问题标题】:crontab does not really start schedulecrontab 并没有真正开始计划
【发布时间】:2021-09-25 00:38:10
【问题描述】:

在 laravel 中,我有一个 SnapShot 方法可以将数据复制到统计模型中。

当我跑步时

/var/www/laravel/artisan  schedule:run

数据被添加到统计表中。

现在我在 /etc/crontab 中添加了以下行

* * * * *  php /var/www/laravel/artisan schedule:run >> dev/null 2>&1

在我的 /var/log/syslog 我读到:

 Jul 16 08:53:01 cluego CRON[24524]: (root) CMD (cd /usr/bin/php7.4  && php artisan schedule:run /dev/null 2>&1)
Jul 16 08:53:01 cluego CRON[24523]: (CRON) info (No MTA installed, discarding output)
Jul 16 08:54:01 cluego CRON[24599]: (root) CMD (php /var/www/laravel/artisan schedule:run /dev/null 2>&1)
Jul 16 08:54:01 cluego CRON[24598]: (CRON) info (No MTA installed, discarding output)


laravel.log 显示:

[2021-07-16 09:25:01] production.ERROR: No arguments expected for "schedule:run" command, got "/dev/null". {"exception":"[object] (Symfony\\Component\\Console\\Exception\\$
[stacktrace]

当我手动运行时,我得到以下结果:

root@xxxx:/var/www/laravel# php artisan schedule:run
Running scheduled command: '/usr/bin/php7.4' 'artisan' statistics:snap > '/dev/null' 2>&1

一个数据点被添加到统计表中,就像它应该做的那样。

谁能看到为什么 cronjob 没有像手动 schedule:run 一样运行 statistics:snap 命令?

【问题讨论】:

  • 您是否重新加载了 cron 并重新启动它?

标签: laravel cron schedule


【解决方案1】:

问题是您的 coron 作业格式错误。从文档看它应该是这样的:

* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

所以在你的情况下它应该是这样的:

* * * * * cd /var/www/laravel && php artisan schedule:run >> /dev/null 2>&1

我想您也可以尝试运行您的版本,但使用 php 的完整路径而不是仅 php 或使用 /dev/null 而不是 dev/null

* * * * *  php /var/www/laravel/artisan schedule:run >> /dev/null 2>&1
* * * * *  /path/to/php /var/www/laravel/artisan schedule:run >> /dev/null 2>&1

【讨论】:

  • 谢谢你。显然我在这里使用了错误的教程。你的回答做到了!
猜你喜欢
  • 2018-07-05
  • 2011-01-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-17
  • 2011-08-18
相关资源
最近更新 更多