Skip to content
Advertisement

Laravel + Crontab not working

I am trying to set up scheduler in Laravel.

Here is my crontab which I debugged and works fine – atleast with my cron job

* * * * * /bin/echo "foobar" >> /my_path/example.txt 

I don’t know if this one works:

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

Here is my schedule function in Kernel:

   protected function schedule(Schedule $schedule)
    {
         $schedule->command('inspire')
                 ->everyMinute();
    }

When I am in my project and try php artisan inspire it actually works, so I expected it to fire every minute, but it won’t do anything. Nothing happens.

Any ideas?

Advertisement

Answer

This part just puts the output into oblivion so you’ll never see it:

>> /dev/null 2>&1

Why not try:

* * * * * php /var/www/myproject/artisan schedule:run >> /my_path/example.txt 

And check to see if the cron is run in /my_path/example.txt

The default inspire command essentially just echo’s a quote so the only way to see it in a cron is to output it to a file on the server.

You can do this using something similar to this:

$schedule->command('inspire')->everyMinute()->appendOutputTo($filePath);

Further details: https://laravel.com/docs/5.4/scheduling#task-output

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement