0

I need to get this to run in a cron file in /etc/cron.d/:

*/15 * * * * php -f /var/www/nextcloud/cron.php

...but, my scripts don't run. It's permissions are set to 644 and I need to create it with a Shell/BASH script. I'm using:

echo "*/15 * * * * php -f /var/www/nextcloud/cron.php" > /etc/cron.d/nccron

What am I doing wrong?

Jesse
  • 217
  • 3
  • 12

2 Answers2

1

There is an much easier way (must be done as root user)

echo '*/15 * * * * www-data php -f /var/www/nextcloud/cron.php' > /etc/cron.d/wwwcron

I'd use SINGLE quotes not DOUBLE quotes to prevent any possibility of expansion of the '*' metasymbol.

mdpc
  • 11,856
  • 28
  • 53
  • 67
0
  1. To run a PHP cron job, www-data needs to do a crontab job itself, using php -f as the [user] inside the cronjob line:

*/15 * * * * php -f /var/www/nextcloud/cron.php

(These are Nextcloud instructions. They got it right, don't try to hack this, in my case.)

  1. www-data must run the cron job itself as a crontab (not /etc/cron.d, et al)

Normally, this is set up from the terminal:

Running as root in this example...

crontab -u www-data -e ...add the cronjob string (above).

crontab -u www-data -l ...and it should match.

But, I need this done as a script, not crontab -e in the terminal.

  1. Do this via shellscript (danger?):

crontab jobs are in: /var/spool/cron/crontabs/USER

with permissions: -rw------- ... www-data crontab

The script that worked:

Running as root in this example...

echo "*/15 * * * * php -f /var/www/nextcloud/cron.php" >> /var/spool/cron/crontabs/www-data
chown www-data:crontab /var/spool/cron/crontabs/www-data
chmod 600 /var/spool/cron/crontabs/www-data

Oh, Happy Day!

Jesse
  • 217
  • 3
  • 12