Best way to add crontab OCC/cron.php jobs?

There seems to be a couple ways I can define cron jobs in crontab. Mine are below. Some use “php -f”, such as the one for cron.php, while others do not use “-f”, but it stills seems to work fine, specifically for the OCC commands. My assumption is that a third way is to remove “php” and just execute OCC directly.

Can someone explain the best way to execute the commands below? Is -f needed? Thanks.

*/15 * * * * php -f /var/www/html/nextcloud/cron.php
*/30 * * * * php /var/www/html/nextcloud/occ preview:pre-generate
0 4 * * * php /var/www/html/nextcloud/occ preview:generate-all --path=“ryan/files/Pictures”
0 5 * * * php /var/www/html/nextcloud/occ files:scan --path=“ryan/files”

The usage line for php says:
Usage: php [options] [-f] [–] [args…]
So the -f is optional. I would include it anyway for clarity.
The direct way to execute the php files in the nextcloud directory will not work, as they are not flagged as executable. You could change that, but the next upgrade will remove the executable flag again.

Makes perfect sense. I realized I’ve been setting occ as executable after each update so that I can run things via bash as needed. Thank you.

1 Like