Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 950
prgrm Avatar asked Feb 27 '17 10:02

prgrm


People also ask

How do I know if cron laravel is working?

Using Output In a Script to Show a Running Cron Job You can add a line of code in your existing script to output a result when the script is run. If the result of this command produces an output, then you can use this output to confirm that your cron script is running.

How do I run a cron job in laravel localhost?

1) You can run php artisan list command in cmd and find your cron. 2) After find your cron, then you can run php artisan yourcron . You can follow this link for more details about cron job. Hope this work for you!

What is cron in laravel?

To automate these tasks I use Laravel Cron Job scheduling. Cron is the task scheduler mechanism of Unix/Linux operating systems. Cron schedules tasks based on a pre-specified time period like numbers of days, weeks, months, or even specific dates and time.


2 Answers

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

like image 62
Rhu Avatar answered Oct 13 '22 10:10

Rhu


Am also using laravel 4.2, Here is my Cron command which currently working good.

0   0   *   *   *   /usr/local/bin/php /*****/******/public_html/artisan command:firemyevent

Hope It will help you.

like image 43
Muthu17 Avatar answered Oct 13 '22 10:10

Muthu17