How to make Cron job works, followed documentation didn't work out :)

Sorry, I referred to the log entries you provided
Dec 6 10:45:01 CRON[23343]: (www-data) MAIL (mailed 74 bytes of output but got status 0x004b from MTA#012)
and thought it is the context of user www-data your web server is running with.

Maybe you can also provide the output of:
ps -ef | grep -Ei "apache|nginx" | grep -v "grep"

@SyS0p3r I went to my nextcloud file located in my server here : /run/user/1000/gvfs/sftp:host=home6XXXXX.1and1-data.host/nextcloud
I did ls -alh and it gave me :

ls: impossible d’ouvrir le répertoire ‘.’: Permission non accordée

Which means in English :
ls: impossible to open the directory "." : authorisation not granted

To continue to answer you :

  • I have no idea if my provider allows me to run cronjobs. How can I know ?
  • To run php I did :
    ** sudo -s
    ** ssh u8XXXXX@home6XXXXX.1and1-data.host
    ** cd ~/nextcloud
    ** php -f ./cron.php

and it gave me :

< br />
< b>Parse error< /b>: syntax error, unexpected ‘{’ in < b>/homepages/4X/d6XXXXXX/htdocs/nextcloud/cron.php< /b> on line < b>40< /b>< br />

@Schmu I tried to run ps -ef | grep -Ei "apache|nginx" | grep -v "grep" but when I press enter, nothing happens ?

Do you enter your server with sftp of directly ssh? I thnk you need to contact your hosting provider (1and1) and ask them if and how you can run cronjobs. It’s not a nextcloud issue, but it’s just not clear how you connect to the server and if you have cron permissions at all. Just tell them you need to create a cronjob for cron.php in the nextcloud folder and if they can advise you about how to do so.

1 Like

I called my hosting provider (1and1) and they assured me I can create Cron jobs. I went to read their documentation :

I followed step by step the tutorial and it appears that despite all we’ve done together no crontab was created for the user provided by 1&1. When I did in SSH :

  • crontab -l
  • result : no crontab found (or something like it)

Then I tried what was said in the tutorial and did :

  • crontab -e
    which opened a new crontab file, with Vim editor. I went to the last line, pressed the key “i” (for insert) and put :
    */15 * * * * /usr/bin/php /kunden/homepages/4X/d6XXXXXX/htdocs/nextcloud/cron.php
  • then ESC and wrote :x pressed enter to quit and save the file.

Then I checked if there was a crontab for the user :

(uiserver):u8XXXXX:~$ crontab -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 comman
*/15 * * * * /usr/bin/php /kunden/homepages/4X/d6XXXXXXX/htdocs/nextcloud/cron.php

I did a service ssh restart

It seems it’s working ! :hugs: :star_struck::innocent:

But… :sweat_smile: still red flag in the Nextcloud admin pannel…

Any other idea ? :grin:

Well i’m kinda out of options. Might be a missing php module. if you do a php -m to see if you’re missing any php modules required by nextcloud https://docs.nextcloud.com/server/12/admin_manual/installation/source_installation.html#prerequisites-label

As mentioned earlier, the cron job needs to be defined for the correct user. The documentation of nextcloud reads:

Cron

Using the operating system cron feature is the preferred method for executing regular tasks. This method enables the execution of scheduled jobs without the inherent limitations the Web server might have.

To run a cron job on a *nix system, every 15 minutes, under the default Web server user (often, www-data or wwwrun), you must set up the following cron job to call the cron.php script:

# crontab -u www-data -e
*/15  *  *  *  * php -f /var/www/nextcloud/cron.php

You can verify if the cron job has been added and scheduled by executing:

# crontab -u www-data -l
*/15  *  *  *  * php -f /var/www/nextcloud/cron.php

Source: Defining Background Jobs — Nextcloud 12 Server Administration Manual 12 documentation

1 Like

I thought about that too, but was under the impression that the default-user is the webserver-user. He doesn’t have full controll over the server, it’s just web hosting and I’m not really sure what the right user/permission is in that case. Running the cron.php from the commandline as the wrong user should normally result in a warning, telling you to run it as the webserver-user, and not some kind of parse-error.

But Tuhadj might as well check which user owns all the NC-files: “ls -la /kunden/homepages/4X/d6XXXXXX/htdocs/nextcloud”

Checking the php-modules, as suggested by SyS0p3r, is probably a good idea.

Well @SyS0p3r I did a check up of all php modules, I was missing a pdo_sqlite3 (for now I am using Sqlite, I’ll change to MariaDB but it is my next target after getting done with Cron). I installed pdo_sqlite3 and no change, red flag still in place for Cron.

@Schmu, when I logged as root :

  • I already had a crontab for www-data it said it is in
    /tmp/crontab.ZuQ8VA/crontab
  • and when I logged via SSH with the user given by my host provider, it told me :
    must be privileged to use -u

Thanks for your help, we will succeed ! :yum:

It’s a longshot, but could you run

ls -la /usr/bin | grep php

to see which php-binaries are available.

If there is a “/usr/bin/php7.1-cli” or something like that available, try running the cron php with that:

/usr/bin/php7.1-cli -f /kunden/homepages/4X/d6XXXXXX/htdocs/nextcloud/cron.php

Sorry for the late response @TheMindFlayer, here is what I get when I enter ls -la /usr/bin | grep php :

lrwxrwxrwx 1 root root 21 july. 29 22:26 php → /etc/alternatives/php
-rwxr-xr-x 1 root root 4385840 déc. 7 21:49 php7.0
-rwxr-xr-x 1 root root 4538400 déc. 14 17:25 php7.1

No sign of /usr/bin/php7.1-cli ?

Cron job are enabled, I made it sure with my hosting provider.
They won’t give me a hand, they consider it isn’t their job.

Any other idea ? :slight_smile:

Hm, this tutorial suggested that there might be one and that the default php-cli-version is 4.4. It might be outdated though.

I’m still convinced that this is a PHP-issue. PHP doesn’t understand what’s on line 40 of your cron.php. But I have no clue about PHP or the PHP-setup on your server.

You could try to run:

/usr/bin/php7.1 -f /kunden/homepages/4X/d6XXXXXX/htdocs/nextcloud/cron.php

Does the output change?

You could try to reupload the cron.php, just in case it got damaged. That’s not likely though.

Another posibility to check the PHP-Version would be creating a PHP-file with the following content:

<?php echo phpversion(); ?>

You can call it version.php or whatever, it doesn’t matter and then compare the outputs of:

/usr/bin/php -f /path/to/version.php

and

/usr/bin/php7.1 -f /path/to/version.php

If both report 7.1, you might have to check what’s on line 40 of your cron.php and why that may fail.

1 Like

I know the thread is old, but it didn’t seem to offer a working solution and reasons why offered suggestions might fail. One of my nextcloud instances runs on shared hosting. There is no www-data user and there are no files in /var/log for troubleshooting. I got the cron job running with:

0,15,30,45 * * * *
cd /home/username/public_html/nextcloud; /usr/local/bin/php -f /home/username/public_html/nextcloud/cron.php

You should always cd to the path of the php script before running it in case the php script looks for files relative to the current folder. You also need to specify the php command with its full path because commands that run from cron do not load all the paths that are loaded from the ssh terminal shell because cron commands do not load /etc/bashrc or ~/.bashrc or ~/.bash_profile beforehand.
To find the path of your php command, type 'which php' into the ssh terminal window.
If you run a cron job for the command 'set > /tmp/vars.txt' and then from the terminal type 'cat /tmp/vars.txt | grep PATH' you will notice that the PATH variable only has /usr/bin and /bin. There is no /usr/local/bin etc so the php command is not found and cannot run. Setting the script to run on the hour, 15 past etc made more sense to me rather than every 15 minutes.

1 Like