Update crontab with script?

Nextcloud version (eg, 18.0.2): 20.0.5
Operating system and version (eg, Ubuntu 20.04): Ubuntu 20.04
Apache or nginx version (eg, Apache 2.4.25): Apache/2.4.41 (Ubuntu)
PHP version (eg, 7.1): PHP 7.4.9

The issue you are facing:
Hello,

So I am trying to create a update script for Nextcloud where it will be able to update Nextcloud to new versions and fix all the errors that can occur after an update (for example db:add-missing-indices error).
And to be able to create an auto update script, then I will need to inactive the crontab just to be on the safe side (Upgrade manually — Nextcloud latest Administration Manual latest documentation).

The thing is that I can’t find a way to update Crontab so that I have a # infront of the string.

I have tried with:
sed -i (With no luck):
crontab -u www-data -l | { sed -i 's/*/5 * * * * php -f $nextcloudLocation/cron.php > /dev/null 2>&1 / #*/5 * * * * php -f $nextcloudLocation/cron.php > /dev/null 2>&1/'; } | crontab -u www-data -

I have even tried to create a cron in /etc/cron.d/nxtc and when I try to run that, then I get an error in Nextclodu that Crontab havn’t run for 50 years…

So how can I create a cron that Nextcloud can recognize and that I can update?

Hi @rojz,

Your issue doesn’t appear to be a Nextcloud issue, but rather an Ubuntu / cron issue.

Did you do a web search for ‘programatically edit cron ubuntu’ ?

I have tried alot trust me, but I think that I got it to work now… I hope. :stuck_out_tongue:

did you look in /var/spool/cron/crontabs?

Hi @rojz

The search I did returned 5 various solutions on the first Google search page, then reams more?
Took less than 60 seconds? Which search engine(s) did you use?

If you now have a working solution, maybe you’d like to post it here, so anyone who finds this topic looking for something similar will have the solution, or at least a good head-ups.

The solutions below should get the vast majority of people going in the right direction.

I did get it to work with /etc/cron.d/

root@test-nxtc-server-jpbjxl53ei42:/home/ubuntu# cat /etc/cron.d/nxtc
#*/5  *  *  *  * www-data php -f /var/www/html/nextcloud/cron.php > /dev/null 2>&1

Then change it within the script with:
sed -i "s/*\/5/#*\/5/" /etc/cron.d/nxtc
and
sed -i "s/^#//" /etc/cron.d/nxtc

1 Like