0

I have a hard time running cron job on Digitalocean. I noticed there are two different cron files, I get to one by getting to /etc/crontab and other one by entering the command crontab -e.

To make it more confusing, both of those have somewhat different "layout". First one:

* *     * * *   root    php /var/www/Laravel artisan schedule:run >> /home/laravel.log

and second one:

* * * * * php /var/www/Laravel artisan schedule:run >> laravel.log

Here is Laravel scheduler part:

protected $commands = [
    'App\Console\Commands\SyncAPIs',
];

/**
 * Define the application's command schedule.
 *
 * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
 * @return void
 */
protected function schedule(Schedule $schedule)
{
    $schedule->command('media:sync')->everyThirtyMinutes();

    // sync for yesterday to eliminate discrepancies
    $schedule->command('media:sync ' . Carbon::yesterday())->dailyAt(6);
}

The thing is that the laravel.log does get created, but I see nothing in it, and I don't know if my commands actually get ran. Does that mean that cron IS actually running? How can I debug the issue as I don't see in the database that cron filled it. When I go to the folder /var/www/Laravel and execute the commands which are supposed to be called in scheduler, dataabse fills correctly.

Norgul
  • 4,613
  • 13
  • 61
  • 144
  • `crontab -e` edits the crontab of the *current* user. `/etc/crontab` is system-level stuff that runs as root. You will *typically* want the one from `crontab -e`. – ceejayoz Oct 25 '17 at 20:46
  • Try to use `... >> laravel.log 2>&1` [Redirect all output to file](https://stackoverflow.com/questions/6674327/redirect-all-output-to-file). You are not logging errors – ljubadr Oct 25 '17 at 21:13
  • Also, look into [Writing Output to the console](https://laravel.com/docs/5.5/artisan#writing-output). Or you could use laravel `Log::error()` or `Log::info()` and check your **storage/logs/laravel.log** – ljubadr Oct 25 '17 at 21:17
  • also, try to specify full path to log file `... >> /vvar/www/html/laravel.log`, or where ever you want your log to be stored... – ljubadr Oct 25 '17 at 21:20

3 Answers3

1

cd ~
crontab -u root -e
* * * * * php /var/www/laravelprojectname/artisan schedule:run 1>> /dev/null 2>&1
service cron restart
grep -i cron /var/log/syslog|tail -3

I think this should help

0

May be you need to change this line :

* * * * * php /var/www/Laravel artisan schedule:run >> laravel.log

to :

* * * * * /usr/bin/php /var/www/Laravel artisan schedule:run >> laravel.log
MEDALI
  • 55
  • 5
  • I tried...in both cases file gets created with nothing in it and nothing in database updated – Norgul Oct 25 '17 at 20:58
  • Try this : `/usr/bin/php /var/www/Laravel artisan media:sync` if you don't have any output in your console that mean there is no Log writed and it's normal to have an empty log file – MEDALI Oct 25 '17 at 21:12
  • do you mean to put this in cron instead of `schedule:run`? – Norgul Oct 25 '17 at 21:27
  • it doesn't execute. It only executes when actually in Laravel folder – Norgul Oct 25 '17 at 21:33
  • Yes sorry I mean you have to do this : `cd /var/www/Laravel && php artisan media:sync` – MEDALI Oct 25 '17 at 21:38
0

I found an answer being actually:

* * * * * php /var/www/Laravel/artisan schedule:run >> laravel.log

php works globally, but artisan needs to be shown the path which is in my Laravel main folder

Norgul
  • 4,613
  • 13
  • 61
  • 144