I'm trying to run backup using cron, i'm using spatie-laravel-backup it is working when i run it manually but when i run it using cron using this path on server:
/home/user/public_html && php artisan backup:run >> /home/user/logs 2>&1
and i'm getting this
/bin/bash: /home/user/public_html: Is a directory"
kernel.php
protected function schedule(Schedule $schedule)
{
$schedule->command('backup:run')->daily()->at('10:00');
}
run scheduler from cron
https://laravel.com/docs/8.x/scheduling#running-the-scheduler
* * * * * cd /home/user/public_html && php artisan schedule:run >> /dev/null 2>&1
then
you can use
protected function schedule(Schedule $schedule)
{
$schedule->command('backup:run')->daily()->at('10:00');
}
Related
as Running The Scheduler says I must run this Command:
* * * * * cd /home/u285707107/domains/dmn.com/ && php artisan schedule:run >> /dev/null 2>&1
but in hPanel Cron Job-s I can't use special characters, so I create cron.sh file as they say
#!/bin/sh
/home/u285707107/domains/dmn.com/ && php artisan schedule:run > /dev/null 2>&1
and in Hostinger Cron Job I run Command:
/bin/sh /home/u00000000/domains/dmn.com/public_html/dmn/app/Console/cron.sh
but it don't works : ( (
My Kernel.php file is:
<?php
namespace App\Console;
use App\Models\Proview;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected function schedule(Schedule $schedule){
$schedule->call(function () {
Proview::query()->update(['today' => 0]);
})->everyMinute();
}
protected function commands(){
$this->load(__DIR__.'/Commands');
require base_path('routes/console.php');
}
}
can someone Help me ?
Just replace the below scripts with yours.
cron.sh
#!/bin/sh
cd /home/u285707107/domains/dmn.com && php artisan schedule:run >> /dev/null 2>&1
Hostinger Cron Job
* * * * * /bin/sh /home/u285707107/domains/dmn.com/public_html/dmn/app/Console/cron.sh
I created a command artisan to make a text file in my path. This command executes correctly by running the command but not for task scheduling in my localhost (not server).
CreateFile class:
protected $signature = 'create:file';
public function handle()
{
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = "parisa";
fwrite($myfile, $txt);
fclose($myfile);
}
Kernel.php:
protected $commands = [
Commands\CreateFile::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->command('create:file')->everyMinute();
}
When I run php artisan schedule:run my command executes only once at that moment. But I want to execute every minute. How to fix it?
Same problem schedule cron job,
my kernal.php
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Log;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
protected $commands = [
// \App\Console\Commands\SecondTable::class,
];
protected function schedule(Schedule $schedule)
{
// $schedule->command('inspire')
//->hourly();
$schedule->call('App\Http\Controllers\Sale\SaleController#sync')->everyMinute();
}
protected function commands()
{
require base_path('routes/console.php');
}
}
manually running a command-> php artisan schedule:run is working good!
but, cronjob run server is not working correctly,
my cron job code,
* * * * * php /laravel project folder/artisan schedule:run >> /dev/null 2>&1
is not working.
Check your cronjob code, it could be something like this:
* * * * * cd path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
It means: every seconds (* * * * *), go to my project folder (cd path-to-your-project), then execute the command (php artisan schedule:run).
The meaning of the last part of the cronjob is explained here: What is /dev/null 2>&1?
I want to create a cron job for test.
When i run the cron in log file appear the line but after not. I set cron job every minute.
I used php artisan schedule:run ..
Command dbTS
public function handle()
{
Log::info('Functioneaza !');
}
Console Kernel
protected function schedule(Schedule $schedule)
{
$schedule->command('dbTS:demo')
->everyMinute();
}
protected $commands = [
Commands\Inspire::class,
Commands\dbTS::class,
];
I have made a scheduler. When I call it with php artisan userRanking it works.
This is the code in Kernel.php:
protected $commands = [
\App\Console\Commands\UserRanking::class,
];
protected function schedule(Schedule $schedule)
{
$schedule->command('userRanking')
->everyMinute();
}
How do I dispatch it so that it runs automatically?
You have to set up a single cron job that calls the schedule runner every minute:
* * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1
Read Laravel's Scheduler docs for more info.