Sometimes NextCloud needs to run a script or command in the background. According to their website guide, you can do this several different ways, such as AJAX, webcron, cron, or with systemd. I’m not an expert, and I didn’t want to re-invent the wheel, so I just followed the guide, choosing the cron option:

root@alaskalinuxuser-PowerEdge-1950:/var/www/nextcloud# crontab -u www-data -e
no crontab for www-data - using an empty one

Select an editor.  To change later, run 'select-editor'.
  1. /bin/nano        <---- easiest
  2. /usr/bin/vim.tiny
  3. /bin/ed

Choose 1-3 [1]: 
crontab: installing new crontab
root@alaskalinuxuser-PowerEdge-1950:/var/www/nextcloud# crontab -u www-data -l
# Edit this file to introduce tasks to be run by cron.
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# For more information see the manual pages of crontab(5) and cron(8)
# m h  dom mon dow   command
*/15  *  *  *  * php -f /var/www/nextcloud/cron.php

I did change the time interval, choosing to run the cron job every 15 minutes, rather than every 5. With only my own family on the server, I don’t see the need to have it run all of the background jobs every 5 minutes. I’m sure that every 15 will be more than enough to take care of my needs.

Linux – keep it simple.

One Reply to “Home Server: Background Jobs With Cron”

  1. We’re a group of
    volunteers and opening a brand new scheme in our community.

    Your website offered us with helpful info to
    work on. you’ve done an impressive
    job and our whole community shall be thankful to you.

Leave a Reply

Your email address will not be published. Required fields are marked *