简体   繁体   English

如何在Linux AMI上为Laravel应用计划年度cron作业?

[英]How to schedule a yearly cron job for a Laravel app on Linux AMI?

I'm trying to set up a cron job for the 1st of January on my AWS EC2 instance for ec2-user . 我正在尝试在ec2-user AWS EC2实例上为1月1日设置cron作业。 When I do crontab -u ec2-user -l , it shows the following output: 当我执行crontab -u ec2-user -l ,它显示以下输出:

* * * * * usr/bin/php /var/www/html/artisan schedule:run >> /dev/null 2>&1

But even though the following was set up in Kernel.php , the job never fired: 但是,即使在Kernel.php中设置了以下Kernel.php ,该工作也从未触发:

protected $commands = [
    // Commands\Inspire::class,
    Commands\TestYearlyJob::class,
];

protected function schedule(Schedule $schedule)
{
    $schedule->command('table:test-yearly-job')->cron('0 0 1 1 *')
       ->timezone('Europe/London')
       ->appendOutputTo('../taskscheduler.log');
}

The command itself runs from Artisan (I've double checked), so its logic is fine. 该命令本身是从Artisan运行的(我已经仔细检查过),因此它的逻辑很好。

I'm wondering if there is a way to do it with the ->yearly()->at() scheduling option? 我想知道是否可以通过->yearly()->at()调度选项来实现? Or perhaps with a closure truth test? 还是通过closure真实性测试? But I'm not sure what to put in there for a when() statement. 但是我不确定在when()语句中该放什么。 Please help. 请帮忙。

Reference 参考

I noticed cron function has 6 stars. 我注意到cron函数有6星。 Try ->cron('0 0 1 1 * *') . 尝试->cron('0 0 1 1 * *') Also yearly has the same expression, so you can try either this command(..)->yearly()->timezone(..) 而且yearly具有相同的表达式,因此您可以尝试使用以下command(..)->yearly()->timezone(..)

Update 更新资料

The issue is missing / in usr/bin/php . 问题是缺少/usr/bin/php /usr/bin/php fixed the issue /usr/bin/php解决了该问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM