'Cron job is not working when specify time

I have a Laravel project v8 and I have created a cron job for DB backup

It's working every minute but it is not working when I specify the time for daily.

Project timezone is 'Asia/Kolkata' and my GoDaddy shared server timezone is UTC.

kernel.php

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        // $schedule->command('backup:clean')->everyMinute();
        $schedule->command('backup:run')->cron('51 3 * * *');
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

my cronjob on Cpanel.

enter image description here



Solution 1:[1]

You can run cron like this:

protected function schedule(Schedule $schedule)
{
     $schedule->command('backup:run')->dailyAt('03:51');
}

Solution 2:[2]

Replace your kernel.php

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;

class Kernel extends ConsoleKernel
{
    /**
     * Define the application's command schedule.
     *
     * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
     * @return void
     */
    protected function schedule(Schedule $schedule)
    {
        $schedule->command('backup:clean')->everyMinute();
    }

    /**
     * Register the commands for the application.
     *
     * @return void
     */
    protected function commands()
    {
        $this->load(__DIR__.'/Commands');

        require base_path('routes/console.php');
    }
}

And after this set cronjob on Cpanel with the time on which you want to execute

Check that the given time in cpanel the cron will work definitely

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Akash Bhalani
Solution 2 Ali