IN a laravel I have a SnapShot method to copy data to a statistics model.
When I run
/var/www/laravel/artisan schedule:run
data are added to the Statistics-table.
Now I have added the following line to /etc/crontab
* * * * * php /var/www/laravel/artisan schedule:run >> dev/null 2>&1
In my /var/log/syslog I read:
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)
The laravel.log shows:
[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]
when I run manually I get the following result:
root@xxxx:/var/www/laravel# php artisan schedule:run
Running scheduled command: '/usr/bin/php7.4' 'artisan' statistics:snap > '/dev/null' 2>&1
and a data point is added to Statistics-table, just as it is supposed to.
Can anyone see why the cronjob is not running the statistics:snap command, just like the manual schedule:run does?
The problem is that your coron job is wrongly formatted. From the documentation it should look like this:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
So in your case it should look like:
* * * * * cd /var/www/laravel && php artisan schedule:run >> /dev/null 2>&1
I guess you could also try running your version but with the full path to php instead of only php
or using /dev/null
instead of 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