Nextcloud version (eg, 20.0.5): 26.0.0
Operating system and version (eg, Ubuntu 20.04): 18.04
Apache or nginx version (eg, Apache 2.4.25): 2.4.29
PHP version (eg, 7.4): 8.1
If it still doesn’t work try it without the 2>&1 | logger -t mycmd part. I’m not sure what this is supposed to do and whether the syntax is correct or not.
If your goal is to write the output to separate log file you could try this:
Honestly, this seems odd, and I don’t know in which configuration on which platform this would be correct.
On any version of ubuntu at least since 18.04
Why? How would it know that this is a php script that it has to parse and execute?
If I understand correctly, occ is a self contained binary file. Just try to run the same command in the terminal without “php” (for example, sudo -u www-data /var/www/nextcloud/occ preview:pre-generate). I use similar command to update music library in music app.
Ok. Not sure why this is working for you… Maybe you have created an alias or some variable globally on your system…?
On my system (Ubuntu 20.04) I get an error when I run it without php:
sudo: /var/www/html/nextcloud/occ: Befehl nicht gefunden (Command not found)
However I created a few bash aliases to make my life easier, when i have to manually run occ commands or for upgrading my Nextcloud.
alias ncupdate='sudo -u www-data php /var/www/html/nextcloud/updater/updater.phar'
alias nocc='sudo -u www-data php /var/www/html/nextcloud/occ'
So I just have to enter nocc <command> in order to run any occ commands or ncupdate in order to start the Nextcloud Updater.
Regardless of that, I would recommend to always use the full commands and paths in a crontab, unless you know exactly what you are doing and why you are doing it differently, because depending on how the maintainers of your distro configured things, aliases or variables may not be expanded to a non-interactive shell.
Anyways, if it works for you that’s of course fine, but I think it’s rather unsuitable as a general recommendation.