Help setting a crontab

Nextcloud version (eg, 20.0.5): 26.0.1 (tried also with 25.0.3)
Operating system and version (eg, Ubuntu 20.04): NextcloudPi running in a proxmox environment
Apache or nginx version (eg, Apache 2.4.25): `how can i found it?
PHP version (eg, 7.4): 8.1.16

The issue you are facing:
I’m unable to set a cronjob in cronfile

Is this the first time you’ve seen this error? (Y/N): Y

Steps to replicate it:

  1. run sudo -u www-data crontab -e
  2. add line */10 * * * * www-data php -f /home/nextcloud-news-filter/ | grep -E >
  3. run crontab -u www-data -l

Thanks in advance for any hint!

my crontabs looks like this:

25 5 * * 0 /pathto/scripts/ &>/dev/null

i list the contabs with: crontab -l
i save my crontabs in “crontab_root” (crontab -l > crontab_root)
i’m activating my crontab with: crontab crontab_root

In general you should give the full path of the command or you can put the PATH variable into crontab (as example):

#minute Hour Day of Month Month Day of Week Command

(0-59) (0-23) (1-31) (1-12 or Jan-Dec) (0-6 or Sun-Sat)


In general try first run your command in your shell, to see if it runs as expected


if i run with root user “/home/nextcloud-news-filter/” I can see it works.

Regardin the rest of your comment can you please be more specific? I’m no expert in cron or in programming in general sorry.


with sudo -u www-data crontab -l I see
*/5 * * * * php -f /var/www/nextcloud/cron.php --define apc.enable_cli=1
*/10 * * * * www-data php -f /home/nextcloud-news-filter/ | grep -E ‘(filter|marking as read)’ 2>&1 >>/home/nextcloud-news-filter/nextcloud-news-filter.log

Then if I run sudo -u www-data crontab -l > crontab_root
nothing happens.

Finally If I run sudo -u www-data crontab crontab_root
I read crontab_root: Permission denied

Imho your error is the “www-data” in the second line.

If you create cron jobs with the crontab mechanism, crontab files are created for individual users and they do not have the username field in its syntax unlike the system-wide crontab /etc/crontab where you don’t have to run the ‘crontab’ command to install the new version when you edit the file. That file have a username fields that none of the other crontabs do.

It should look like this when using the ‘crontab’ command:

*/5 * * * * php -f /var/www/nextcloud/cron.php --define apc.enable_cli=1
*/10 * * * *  /home/nextcloud-news-filter/ | grep -E ‘(filter|marking asread)’ 2>&1 >>/home/nextcloud-news-filter/nextcloud-news-filter.log
(www-data removed)

I hope this helps.

Check this out with your example: - The cron schedule expression editor

First of all you do no need to specify user in crontab, because you are editing crontab for this specific user. In this case line:

shall be */10 * * * * /home/nextcloud-news-filter/ | grep -E ....

Second, you tries to run python script with php, I delete both in example above.

Than you have to check if your script is executable under this user at all, simply run to see if it works:

sudo -u www-data /home/nextcloud-news-filter/
1 Like

this command does not works

root@nextcloudpi:~# sudo -u www-data /home/nextcloud-news-filter/

sudo: unable to execute /home/nextcloud-news-filter/ Permission denied

So i changed rights to 0777 and now it works in prompt.

No signal from cronjob so I removed also php -f.

Still no signal.

I know because I deleted log and waited. It doesn’t come back (while it does if i run the command using prompt)

Usually 755 should be enough to execute anything.

Than you have to add whole command from the cron to the shell and test if it is executable. Probably user has no right to create logs. Just do as above, add to the following command you cron command:

sudo -u www-data <WHOLE_COMMAND_HERE>
# e.G.
sudo -u www-data /home/nextcloud-news-filter/ | grep -E ‘(filter|marking asread)’ 2>&1 >>/home/nextcloud-news-filter/nextcloud-news-filter.log

Then you have to troubleshoot, remove logs forwarding at the and to see if output exist, in this case problem could be in logs permissions.

OK I changed permission as your suggestion and lauch command in prompt:

root@nextcloudpi:~# sudo -u www-data /home/nextcloud-news-filter/ | grep -E ‘(filter|marking as read)’ 2>&1 >>/home/nextcloud-news-filter/nextcloud-news-filter.log

but the log file is not updated.

If I run

root@nextcloudpi:~# sudo -u www-data /home/nextcloud-news-filter/

I can see the log messaging. How can I add user www-data to write logs then?


First of all lets check permissions to the file, run:

la -la /home/nextcloud-news-filter/nextcloud-news-filter.log

Than you can test if it is writable for user, e.g.:

sudo -u www-data -w /home/nextcloud-news-filter/nextcloud-news-filter.log && echo Ok || echo Nope

If output is Nope file or path is not writable for this user.