Cron job always stopping after first run

Nextcloud version (eg, 20.0.5): 23.0.0.10
Operating system and version (eg, Ubuntu 20.04): Ubuntu 20.04
Apache or nginx version (eg, Apache 2.4.25): Apache/2.4.41
PHP version (eg, 7.4): 8.0.14

The issue you are facing:
“Last background job execution ran 5 hours ago. Something seems wrong.”
I have configured cron jobs the way it is described in the NC manual:

crontab -u www-data -e

Added this to the end:
*/5 * * * * php -f /var/www/nextcloud/cron.php

This is the return I get when asking: crontab -u www-data -l
*/5 * * * * php -f /var/www/nextcloud/cron.php

When I change the the background settings to something else than Cron and change it back to Cron then I get a green signal that everything is working. But this is the only time it works.

Is this the first time you’ve seen this error? (Y/N): No

The output of your Nextcloud log in Admin > Logging:

Error	PHP	Error: Undefined variable $user at /var/www/nextcloud/apps/backup/lib/Service/ExternalFolderService.php#900

    /var/www/nextcloud/apps/backup/lib/Service/ExternalFolderService.php - line 900:

    OC\Log\ErrorHandler::onError()

    /var/www/nextcloud/apps/backup/lib/Service/ExternalFolderService.php - line 822:

    OCA\Backup\Service\ExternalFolderService->prepareStorageConfig()

    /var/www/nextcloud/apps/backup/lib/Controller/LocalController.php - line 308:

    OCA\Backup\Service\ExternalFolderService->getStorages()

    /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 217:

    OCA\Backup\Controller\LocalController->setExternalFolder()

    /var/www/nextcloud/lib/private/AppFramework/Http/Dispatcher.php - line 126:

    OC\AppFramework\Http\Dispatcher->executeController()

    /var/www/nextcloud/lib/private/AppFramework/App.php - line 157:

    OC\AppFramework\Http\Dispatcher->dispatch()

    /var/www/nextcloud/lib/private/Route/Router.php - line 302:

    OC\AppFramework\App::main()

    /var/www/nextcloud/ocs/v1.php - line 62:

    OC\Route\Router->match()

    /var/www/nextcloud/ocs/v2.php - line 23:

    require_once("/var/www/nextcloud/ocs/v1.php")

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
'instanceid' => 'xxx,
'passwordsalt' => 'xxxx',
'secret' => 'xxxx',
'trusted_domains' =>
array (
0 => 'cloud.xxxxx.ch',

),
'datadirectory' => '/home/data',
'dbtype' => 'mysql',
'version' => '23.0.0.10',
'overwrite.cli.url' => 'http://cloud.xxxxx.ch',
'dbname' => 'nextcloud',
'dbhost' => 'localhost',
'dbport' => '',
'dbtableprefix' => 'oc_',
'mysql.utf8mb4' => true,
'dbuser' => 'xxx',
'dbpassword' => 'xxxxxx',
'installed' => true,
'defaultphoneregion' => 'CH',
'twofactor_enforced' => 'true',
'twofactorenforcedgroups' =>
array (
0 => 'admin',

),

'twofactorenforcedexcluded_groups' =>
array (
),

'maintenance' => false,
'mailfromaddress' => 'nextcloud',
'mail_smtpmode' => 'smtp',
'mail_sendmailmode' => 'smtp',
'mail_domain' => 'xxx',
'mail_smtpauthtype' => 'LOGIN',
'mail_smtphost' => 'eos.ssl.hosttech.eu',
'mail_smtpport' => '465',
'mail_smtpauth' => 1,
'mail_smtpname' => 'xxxx.ch',
'mail_smtppassword' => 'xxxx',
'mail_smtpsecure' => 'ssl',
'appinstalloverwrite' =>
array (
0 => 'documentserver_community',
'memcache.local' => '\OC\Memcache\APCu',
),

);

The output of your Apache/nginx/system log in /var/log/____:

[Wed Jan 05 00:00:01.950054 2022] [mpm_prefork:notice] [pid 828] AH00163: Apache/2.4.41 (Ubuntu) OpenSSL/1.1.1f configured -- resuming normal operations

[Wed Jan 05 00:00:01.950079 2022] [core:notice] [pid 828] AH00094: Command line: '/usr/sbin/apache2'

Logging at warning level to file: /tmp/coolwsd.4TgdrsGYY9/coolwsd.log

[Wed Jan 05 07:21:57.581908 2022] [php:warn] [pid 9434] [client 10.0.0.3:55430] PHP Warning:  Undefined array key "Content-Type" in /var/www/nextcloud/apps/richdocumentscode/proxy.php on line 346

[Wed Jan 05 07:21:57.581939 2022] [php:warn] [pid 9434] [client 10.0.0.3:55430] PHP Warning:  Undefined array key 1 in /var/www/nextcloud/apps/richdocumentscode/proxy.php on line 347

Security: coolforkit incorrect user-name, other than 'cool'

Init vcl

preload: merged ucpchelp1 msforms vbaobj pcr vbaswobj sw animcore hwp chartcore solver sc wpftcalc ucpcmis1 wpftdraw sd svgfilter graphicfilter wpftimpress sdfilt sm pdffilter PresentationMinimizer >

Disabled: ucpftp1 rptxml dbu rptui rpt mork odbc sdbc2 cmdmail PresenterScreen abp dbp

Allowlisted languages: deDE el enGB enUS esES frFR hu it nl ptBR pt_PT ru

Preloading dictionaries: deDE enUS frFR itIT nlNL ptBR ruRU enGB nlBE ptPT es_ES

Preloading thesauri: deDE enUS frFR itIT nlNL ptBR ruRU enGB nlBE ptPT es_ES

Preload icons

Preload languages

Preload fonts

Ready to accept connections on port 9983.

cat: /sys/class/net/wlp58s0/speed: Invalid argument

cat: /sys/class/net/wlp58s0/duplex: Invalid argument

I’m not sure if that marks a nextcloud-problem.
though the logs you posted indicate that there’s a problem with backup and collabora.
to be on the safe side: would you be so nice and disable both apps and see if that would somehow help with your cron-problems?

other than that: where and how have you installed your instance?

Thank you for your suggestions, I have disabled the backup and the collabora app and restarted the cron. It run once and stopped again.

Here is the latest apache log

[Fri Jan 07 00:00:02.099709 2022] [mpm_prefork:notice] [pid 823] AH00163: Apache/2.4.41 (Ubuntu) OpenSSL/1.1.1f configured -- resuming normal operations
[Fri Jan 07 00:00:02.099731 2022] [core:notice] [pid 823] AH00094: Command line: '/usr/sbin/apache2'
[Fri Jan 07 06:49:07.438765 2022] [mpm_prefork:notice] [pid 823] AH00169: caught SIGTERM, shutting down
[Fri Jan 07 06:49:07.563110 2022] [mpm_prefork:notice] [pid 124929] AH00163: Apache/2.4.41 (Ubuntu) OpenSSL/1.1.1f configured -- resuming normal operations
[Fri Jan 07 06:49:07.563155 2022] [core:notice] [pid 124929] AH00094: Command line: '/usr/sbin/apache2'

Logging at warning level to file: /tmp/coolwsd.KEthK5Bpog/coolwsd.log
[Fri Jan 07 06:57:08.858631 2022] [php:warn] [pid 126158] [client 10.0.0.3:54626] PHP Warning:  Undefined array key "Content-Type" in /var/www/nextcloud/apps/richdocumentscode/proxy.php on line 346
[Fri Jan 07 06:57:08.858657 2022] [php:warn] [pid 126158] [client 10.0.0.3:54626] PHP Warning:  Undefined array key 1 in /var/www/nextcloud/apps/richdocumentscode/proxy.php on line 347
[Fri Jan 07 06:57:08.861168 2022] [php:warn] [pid 125581] [client 10.0.0.3:54624] PHP Warning:  Undefined array key "Content-Type" in /var/www/nextcloud/apps/richdocumentscode/proxy.php on line 346
[Fri Jan 07 06:57:08.861184 2022] [php:warn] [pid 125581] [client 10.0.0.3:54624] PHP Warning:  Undefined array key 1 in /var/www/nextcloud/apps/richdocumentscode/proxy.php on line 347
[Fri Jan 07 06:57:08.862581 2022] [php:warn] [pid 126082] [client 10.0.0.3:54615] PHP Warning:  Undefined array key "Content-Type" in /var/www/nextcloud/apps/richdocumentscode/proxy.php on line 346
[Fri Jan 07 06:57:08.862611 2022] [php:warn] [pid 126082] [client 10.0.0.3:54615] PHP Warning:  Undefined array key 1 in /var/www/nextcloud/apps/richdocumentscode/proxy.php on line 347
Security: coolforkit incorrect user-name, other than 'cool'
Init vcl
preload: merged ucpchelp1 msforms vbaobj pcr vbaswobj sw animcore hwp chartcore solver sc wpftcalc ucpcmis1 wpftdraw sd svgfilter graphicfilter wpftimpress sdfilt sm pdffilter PresentationMinimizer >
Disabled: ucpftp1 rptxml dbu rptui rpt mork odbc sdbc2 cmdmail PresenterScreen abp dbp
Allowlisted languages: de_DE el en_GB en_US es_ES fr_FR hu it nl pt_BR pt_PT ru
Preloading dictionaries: de_DE en_US fr_FR it_IT nl_NL pt_BR ru_RU en_GB nl_BE pt_PT es_ES
Preloading thesauri: de_DE en_US fr_FR it_IT nl_NL pt_BR ru_RU en_GB nl_BE pt_PT es_ES
Preload icons
Preload languages
Preload fonts
Ready to accept connections on port 9983.
mrkadmin@mrksrvcloud:/var$ sudo crontab -u www-data -l
[sudo] password for mrkadmin: 
# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command

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

mrkadmin@mrksrvcloud:/var$ 

Thank you so much for your help!