Bonboni's avatar

send email every minute using cron job

I have the following function:

protected function schedule(Schedule $schedule)
{
    $schedule->command('email:users')->everyMinute();
}

when I ad the command

php /home/rain/artisan schedule:run 1>> /dev/null 2>&1

to cpanel as a cron job it works but it doesn't send me a notification email. Cpanel suppose to email me a notification when the cron job runs, but I haven't receive a single email.

I found out that /dev/null 2>&1 is used in cron job when you do not want to send email when cron job runs. So, what the command should be exactly to get emails from cpanel when it runs the cron job?

Also when I run the command artisan schedule:run from shell it runs it only once. I am very curious why do I have to add ->everyMinute(); if it is not going to run every minute? If I want to send it weekly I can setup the cron job. Why do I have to write to add ->weekly(); in the function if cron job is sending it weekly?

0 likes
3 replies
Thyrosis's avatar

Well, the Laravel scheduler takes care of everything for you. The only thing you have to do, is to tell cpanel to run the scheduler every minute to see if it needs to do something.

If you only want the cron to run at the specific times set by you, you should have it perform a task itself, not call the scheduler. E.g., get the cron to wget or curl one of your routes.

Also, if you use >> /dev/null 2>&1, you're actually telling cpanel not to send you an email. It means as much as 'any output you may have, just send it straight to the void. I don't want it'. Get rid of that big and you'll at least get the cpanel output.

1 like
Bonboni's avatar

thanks guys for the info. I have set it up correctly. It works now.

Please or to participate in this conversation.