Issue Running Artisan Command via Cronjob

て烟熏妆下的殇ゞ 提交于 2020-07-07 10:59:39

问题


I'm having a bit of a nightmare getting a crontab/cronjob to run an Artisan command.

I have another Artisan command running via cronjob no problems but this second command won't run.

Firstly, when I do 'crontab -e' and edit the file to contain:

0 0 * * * /usr/local/bin/php  /home/purple/public_html/artisan feeds:send

The cronjob doesn't run at all.

If I go to cPanel and add the cronjob there, it runs but I receive the following error:

open(public/downloads/feeds/events.csv): failed to open stream: No such file or directory

The thing is the file exists and the directories have the correct permissions. If I run the command when logged in via SSH as root or the user purple (php artisan feeds:send) the command runs flawlessly and completes its tasks no problem.

If in cPanel, I edit the cronjob to use:

0 0 * * * php  /home/purple/public_html/artisan feeds:send

I receive the following error:

 There are no commands defined in the "feeds" namespace.

The funny thing is that my other command is registered in the crontab file and works and has no reference in cPanel at all.

Any help would be much appreciated. Just for brevity I have included the command and model that the command uses.

Feed.php Model:

http://laravel.io/bin/1e2n

DataFeedController.php Controller:

http://laravel.io/bin/6x0E

SendFeeds.php Command:

http://laravel.io/bin/BW3d

start/artisan.php:

http://laravel.io/bin/2xV3

FeedInterface.php Interface:

http://laravel.io/bin/LxnO

As you can see there is a GetRates command, which works.


回答1:


Well it looks like I had to cd in to the script directory first before running the command, which now after working it out it makes sense. Easy when you know how eh!

* * * * * cd /home/purple/public_html/ && /usr/local/bin/php artisan feeds:send


来源:https://stackoverflow.com/questions/22785261/issue-running-artisan-command-via-cronjob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!