Background jobs Last job execution ran 2 days ago. Something seems wrong

Nextcloud version 19.0.0
Operating system and version Ubuntu 20.04
Apache 2.4.41
PHP 7.4

Hello
I am new to Nextcloud but after several installs on Hyper-V first to fail my way to learning a little I the instance running on its own machine which runs pretty good. I have been battling the big red Square on last Cron job and have looked everywhere for a solution.
these are the 2 Cron line I inputted
m h dom mon dow command

*/5 * * * * php -f /var/www/nextcloud/cron.php

4 * * * * /usr/bin/php -f /var/www/nextcloud/occ preview:pre-generate

To be honest my main goal here is just to keep the installation clean and get the Green checkmark. which Cron scripts are necessary ?
var/www/nextcloud is where cron.php is stored.
Steps to replicate it: refresh the page
The cron.php file is here.

<?php /** * @copyright Copyright (c) 2016, ownCloud, Inc. * * @author Artem Sidorenko * @author Christopher Schäpers * @author Christoph Wurst * @author Damjan Georgievski * @author Daniel Kesselberg * @author Jakob Sack * @author Joas Schilling * @author Jörn Friedrich Dreyer * @author Ko- * @author Michael Kuhn * @author Morris Jobke * @author Oliver Kohl D.Sc. * @author Robin Appelman * @author Roeland Jago Douma * @author Steffen Lindner * @author Thomas Müller * @author Vincent Petry * * @license AGPL-3.0 * * This code is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License, version 3, * as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License, version 3, * along with this program. If not, see * */ require_once __DIR__ . '/lib/versioncheck.php'; try { require_once __DIR__ . '/lib/base.php'; if (\OCP\Util::needUpgrade()) { \OC::$server->getLogger()->debug('Update required, skipping cron', ['app' => 'cron']); exit; } if ((bool) \OC::$server->getSystemConfig()->getValue('maintenance', false)) { \OC::$server->getLogger()->debug('We are in maintenance mode, skipping cron', ['app' => 'cron']); exit; } // load all apps to get all api routes properly setup OC_App::loadApps(); \OC::$server->getSession()->close(); // initialize a dummy memory session $session = new \OC\Session\Memory(''); $cryptoWrapper = \OC::$server->getSessionCryptoWrapper(); $session = $cryptoWrapper->wrapSession($session); \OC::$server->setSession($session); $logger = \OC::$server->getLogger(); $config = \OC::$server->getConfig(); // Don't do anything if Nextcloud has not been installed if (!$config->getSystemValue('installed', false)) { exit(0); } \OC::$server->getTempManager()->cleanOld(); // Exit if background jobs are disabled! $appMode = $config->getAppValue('core', 'backgroundjobs_mode', 'ajax'); if ($appMode === 'none') { if (OC::$CLI) { echo 'Background Jobs are disabled!' . PHP_EOL; } else { OC_JSON::error(['data' => ['message' => 'Background jobs disabled!']]); } exit(1); } if (OC::$CLI) { // set to run indefinitely if needed if (strpos(@ini_get('disable_functions'), 'set_time_limit') === false) { @set_time_limit(0); } // the cron job must be executed with the right user if (!function_exists('posix_getuid')) { echo "The posix extensions are required - see http://php.net/manual/en/book.posix.php" . PHP_EOL; exit(1); } $user = posix_getpwuid(posix_getuid()); $configUser = posix_getpwuid(fileowner(OC::$configDir . 'config.php')); if ($user['name'] !== $configUser['name']) { echo "Console has to be executed with the user that owns the file config/config.php" . PHP_EOL; echo "Current user: " . $user['name'] . PHP_EOL; echo "Owner of config.php: " . $configUser['name'] . PHP_EOL; exit(1); } // We call Nextcloud from the CLI (aka cron) if ($appMode !== 'cron') { $config->setAppValue('core', 'backgroundjobs_mode', 'cron'); } // Work $jobList = \OC::$server->getJobList(); // We only ask for jobs for 14 minutes, because after 5 minutes the next // system cron task should spawn and we want to have at most three // cron jobs running in parallel. $endTime = time() + 14 * 60; $executedJobs = []; while ($job = $jobList->getNext()) { if (isset($executedJobs[$job->getId()])) { $jobList->unlockJob($job); break; } $job->execute($jobList, $logger); // clean up after unclean jobs \OC_Util::tearDownFS(); $jobList->setLastJob($job); $executedJobs[$job->getId()] = true; unset($job); if (time() > $endTime) { break; } } } else { // We call cron.php from some website if ($appMode === 'cron') { // Cron is cron :-P OC_JSON::error(['data' => ['message' => 'Backgroundjobs are using system cron!']]); } else { // Work and success :-) $jobList = \OC::$server->getJobList(); $job = $jobList->getNext(); if ($job != null) { $job->execute($jobList, $logger); $jobList->setLastJob($job); } OC_JSON::success(); } } // Log the successful cron execution $config->setAppValue('core', 'lastcron', time()); exit(); } catch (Exception $ex) { \OC::$server->getLogger()->logException($ex, ['app' => 'cron']); } catch (Error $ex) { \OC::$server->getLogger()->logException($ex, ['app' => 'cron']); } Thank you

Please execute the commands with the correct user manually and post errors.
Substitute the nextcloud-user www-data with your nextclouduser.

sudo -u www-data php -f /var/www/nextcloud/cron.php

sudo -u www-data /usr/bin/php -f /var/www/nextcloud/occ preview:pre-generate

Post also

sudo -u www-data which php

Hi Devnull
I ran the Command–> sudo -u www-data php -f /var/www/nextcloud/cron.php

which returned --> Background jobs Last job ran 2 minutes ago :smile:
now I ran these commands as Root/ I dont quite understand what you mean Substitute the nextcloud-user .

I entered the Command: sudo -u www-data /usr/bin/php -f /var/www/nextcloud/occ preview:pre-generate. which returned–> There are no commands defined in the “preview” namespace. That was totally my fault and not understanding Cron tab.
I believe installing the Preview generator fixed that.

Now : I ran the command: sudo -u www-data which php .
Which returns–>/usr/bin/php

Now the mystery today is I ran : crontab -l and there were no cron jobs listed??

If I run the Command: sudo crontab -e -u www-data
It returns–>m h dom mon dow command

*/5 * * * * php -f /var/www/nextcloud/cron.php

4 * * * * /usr/bin/php -f /var/www/nextcloud/occ preview:pre-generate

If I run the Command: crontab -e there are no cron jobs listed and at this time I still do not have an active cron job Running . If I enter the command sudo -u www-data php -f /var/www/nextcloud/cron.php.That command resets the background job timer.
your help is most welcomed
Thank you

They are not listed because you missed the nextcloud-user www-data.

Learn more about cron and crontab.

Hello
I never did figure out how to get Crontab working properly, With the installation of Nextcloud I had to do several installs to get it right. I followed the Tutorial on Linuxbabe and read everything I could find. So the Tutorial on Linuxbabe dealt with the known installation errors but now that got me into the Forest of Nextcloud with a nice green checkmark and an A+ rated TLS but did not prepare me what was next, learning how to maintain Nextcloud with a log file full of errors and warnings also a crontab that I cannot find enough information. The server runs fine but I have to manually reset Preview:pre-generate every couple of days. Is there a source where I can gain a better understanding of the backstory of how to maintain this server.

Below is my current most prominent PHP error:
[PHP] Error: Undefined offset: 1 at /var/www/nextcloud/apps/files_external/lib/Lib/Storage/SMB.php#219

{“reqId”:“JUtixaMZZceS0VCj3TM2”,“level”:3,“time”:“2020-07-13T00:11:52+00:00”,“remoteAddr”:“Ip Address”,“user”:“my username”,“app”:“PHP”,“method”:“PROPFIND”,“url”:"/remote.php/webdav/Myserver domain/",“message”:“Undefined offset: 1 at /var/www/nextcloud/apps/files_external/lib/Lib/Storage/SMB.php#219”,“userAgent”:“Mozilla/5.0 (Android) Nextcloud-android/3.12.1”,“version”:“19.0.0.12”,“id”:“5f0ba6c8a9460”}
From what I see here it looks like My Android DAVx5 app???

Also, I’m all googled out on the Crontab Mystery??? “lost in the Linux forest”
I’ve run a Win 2012 r2 for almost 8 years it never gives grief it is the foundation for all things sync and cloud backup and Hyper-v, does everything right so I’m bored with it!!!
Now I’m here to learn.
Below is the kitchen sink of crontab:

   m h  dom mon dow   command
# 0 4 * * * /usr/bin/php -f /var/www/nextcloud/occ preview:pre-generate
# 0 3 * * * www-data /usr/bin/php -f /var/www/nextcloud/occ preview:pre-generate
# 0 1 * * * php /var/www/nextcloud/occ preview:pre-generate

terminal command: sudo -u www-data php -f /var/www/nextcloud/cron.php
then I run : sudo -u www-data /usr/bin/php -f /var/www/nextcloud/occ preview:pre-generate
Gives me a Green: All checks passed.
also commands return:“Command is already running”
terminal command: sudo -u www-data which php
returns: /usr/bin/php I tried to open /usr/bin/php (it is not readable or encrypted)

I am at a loss of what else to do to get this to roll like a… crontab clock.
Thank you all !!

Solved
when adding your cron job I removed the # in front of the line 0 1 * * * php /var/www/nextcloud/occ preview:pre-generate which I saw in someone’s post and now CRON works perfectly.
Thank you