✓ Solved

cron job does not work

Hi,

I read a lot on the support forum about cron jobs.
I followed all the rules. I checked everythings. I stop cron service, restart, check cron status is good … but nope. no job started.

Looking for another idea :-)

thanks
Dominique

10 Replies

✓ Best Answer

/var/www/nextcloud/cron.php should be at least world-readable; i.e., have permissions of:

r--r--r--

It should not be executable by anyone. It doesn't need to be… /usr/bin/php is the executable here. If /var/www/nextcloud/cron.php causes /usr/bin/php to try to modify something, that something needs to have appropriate ownership/permissions to allow that to happen.

I've run into all these problems so you can trust me more than your average politician or used-car salesman… ;-)

-- sw

Well show us the crontab file. Do

crontab -l

and copy the output and paste it here.

Can you post the details of your cron(8) job?

  • How is it scheduled (the output of crontab -l)?

  • If it's short, the exact text of the script or program source that you want cron(8) to run?

Formatting hint… If you put this stuff between 2 rows of ``` (three backticks…to the left of the 1 key on your keyboard), the forum will format it sanely so we can all read it…

like this
like this
like this

-- sw

thanks for the answer. Very appreciated.

here is the cron job :

# cron job Nextcloud
*/5  *  *  *  * php -f /var/www/nextcloud/cron.php

here is the cron job:

# cron job Nextcloud
*/5  *  *  *  * php -f /var/www/nextcloud/cron.php

Your problem is that php(1) is not in the PATH known to cron(8). cron(8) jobs don't run under your login shell so your login environment is not in force for programs run by cron(8).

Change your crontab(1) entry to:

*/5  *  *  *  * /the/full/path/to/php -f /var/www/nextcloud/cron.php

and your job will probably run. You can read more about how to set up a PATH (and other environment variables) for crontab files by reading the man(1) page:

man 5 crontab

The environment that you can set up in a cron(8) job is pretty limited (keep repeating this mantra: cron(8) is not the shell, cron(8) is not the shell…) so don't try to replicate your login environment for cron(8) either. Trying this is a guaranteed fail.

Also, you need to make (damn!) sure that /var/www/nextcloud/cron.php doesn't generate any errors. The only feedback you'll get from them will be via email to root@yourdomain.com (if you've set that up properly). Otherwise, your job(s) will just fail silently.

-- sw

@stevewi

well, I tried your solution but … nope!!

# cron job Nextcloud
*/5  *  *  *  * /usr/bin/php -f /var/www/nextcloud/cron.php

and by the way, thanks for the mantra!

I'll try to execute /usr/bin/php -f /var/www/nextcloud/cron.php directly from the terminal. but no result.

I'll try to take a walk for my mental health and it works ;-)

I'll try to execute /usr/bin/php -f /var/www/nextcloud/cron.php directly from the terminal. but no result.

Does /var/www/nextcloud/cron.php leave any tracks? If it doesn't, you can't credibly say that "cron job doesn't work". Make it write the time of day to some file in /tmp and start watching the content of that file with tail -f. Your job runs every 5 minutes so you shouldn't have to wait very long to see some results.

If you want to keep the log you create, make logrotate rotate it periodically…always a good plan for any service you develop/implement.

-- sw

@stevewi

ok, I'll try that
thanks for your patience.
some news soon

Is the cron job output the same if you run

sudo crontab -u www-data -l

If not, try to add the job to:

sudo crontab -u www-data -e

Nextcloud doc:

Use system cron service to call the cron.php file every 5 minutes. The cron.php needs to be executed by the system user "www-data".

Also check http(s)://< domain/IP >/index.php/settings/admin
IT has to be set to cron(maybe default).

thanks guys for your help.
Really appreciated.
see you.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct