Crontab when NC installed by snap

Hello,
When running occ commands I first cd to this directory </snap/bin>
then I run <sudo ./nextcloud.occ preview:pre-generate>
how do I write this in <sudo crontab -e> in one step? and how do I confirm it is correct

what I guessed but didn’t work
<0 3 * * * ./snap/bin/nextcloud.occ preview:pre-generate>
was trying to run it at 3am everyday.

everyone else seems to go to a directory called occ and run the commands there but I don’t have occ directory I have nextcloud.occ.

Any help will be appreciated
Sam

Have you tried running the command manually, you put into your crontab?

Try executing the command:

/snap/bin/nextcloud.occ preview:pre-generate

If that works and gives you the result you want, you can add this to your crontab:

0 3 * * * /snap/bin/nextcloud.occ preview:pre-generate

With nextcloud-snap you don‘t have to change the directory. But nextcloud.occ has to be run with sudo (even as root!):

I never tried this, but I think you need to add the following line to the system wide crontab file /etc/crontab (adjust time to fit your needs):

0 3 * * * root sudo nextcloud.occ preview:pre-generate