skip to Main Content

my cronjob not working, and I don’t know where the error is

this is my command in Cpanel

/usr/local/bin/ea-php72/home/host/public_html && php artisan schedule:run >> /dev/null 2>&1

this is my schedule in Kernel

protected function schedule(Schedule $schedule)
    {
        $schedule->call(function () {
            $filename1 = base_path("/CSV/data.csv");
            $filesize1 = filesize($filename1);
            if($filesize1 > 0)
            {
                $file1 = fopen(base_path("/CSV/data.csv"), "r");
                  while (($getData1 = fgetcsv($file1, 10000, ";")) !== FALSE)
                  {
                    DB::table('tbdata')->insert([
                        'ID' => $getData1[0], 
                        'Date_' => $getData1[1],
                        'Date' => $getData1[2],
                        'Status' => $getData1[3], 
                        'Remark' => $getData1[4],
                        'SMS' => $getData1[5]
                    ]);
                  }       
                  fclose($file1);   
              unlink(base_path("/CSV/data.csv"));
            }
        })->daily();
    }

please help me

2

Answers


  1. Chosen as BEST ANSWER

    I got the solution is to create my own log file like this

    cd /home/host/public_html && php artisan schedule:run >> /home/host/public_html/backup.log 2>&1 
    

    Thanks @Daan Meijer


  2. In the cronjob command, this part >> /dev/null 2>&1 tells CPanel to not send errors to you. If you remove that, you’ll probably get emails telling you where the error is.

    Also, you can manually execute the command line /usr/local/bin/ea-php72/home/host/public_html && php artisan schedule:run. You’ll probably find you’re missing a cd in front of that.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search