Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CRON JOB - LARAVEL - OUTPUT

Tags:

cron

laravel

Hi I'm running CRON JOB with Laravel

Function declaration in Laravel

protected function schedule(Schedule $schedule)
{
    echo "test CRON JOB\n";
    $file1 = '1.log';
    $file2 = '2.log';
    $schedule->command('command1')->sendOutputTo($file1);
    $schedule->command('command2')->sendOutputTo($file2);

}

CRON JOB - Setting

pathToArtisan schedule:run 2>&1 >> /home/log/cron_output.log

Log file output (cron_output.log)

test CRON JOB
Running scheduled command: '/opt/alt/php55/usr/bin/php' 'artisan'command1 > '1.log' 2>&1 &
Running scheduled command: '/opt/alt/php55/usr/bin/php' 'artisan' command2 > '2.log' 2>&1 &

The echo in the function schedule is displayed but the ones inside my command 1 and command 2 are not.

I tried

echo "test"; $this->info('test');

No files 1.log or 2.log where created neither /home/log/ or where the Kernel.php file is or Command folder

Any ideas ?

Thank you

like image 561
Léo Coco Avatar asked Aug 31 '16 02:08

Léo Coco


People also ask

What is cron job in Laravel example?

As previously discussed, Laravel has an inbuilt cron job that it uses to manage its tasks. With this scheduler, you can manage your periodical tasks on the server. This scheduler provides an interactive environment to create scheduler commands within your Laravel application.

How do I know if a cron job is running in Laravel?

Run Schedule Command for a test To check if schedule commands have been constructed successfully, run this command. After that, go to the logs folder inside the storage directory, open the Laravel. php cron job file, and check it. Note: You can use this command when you want a Laravel scheduler without a cron job.


1 Answers

You should use the built-in task output method in Laravel.

For example:

$file = 'command1_output.log';
$schedule->command('command1')
         ->sendOutputTo($file);
like image 132
avip Avatar answered Sep 28 '22 20:09

avip