How do I add a cron job?

Trying to use this app [] but I need to add ./occ preview:pre-generate to a system Cron job. How do I go about this? I have installed NextCloud with Snap, if that is important.

Thank you!

sudo nextcloud.occ preview:generate-all

I get this error


I’m not familiar with snap, so please bear with me if I’m writing none-sense which is not working with snap the same way it works on a “normal” unix system.

In general:

  • find out the web server user (www-data/ http/ nginx / …)
  • create the cron job for that user

To find out the web server user you could execute:

ps -ef | grep -E "apache|nginx" | grep -v root | awk '{print $1}' | sort | uniq

Now you have the user which is running your web server. For this user you need to create a cron job:

crontab -e -u <output from command above>

Here you enter the actual job definition (please modify the path to occ accordingly!):

30    *  *  *  * php -f /var/www/nextcloud/occ preview:pre-generate

I hope this helps - if not with your snap installation then at least with the understanding of cron jobs for specific users :smiley:

1 Like