Cronjob doesn't execute cron.php

Hi,

I try to run cron.php within cronjob but it seems like I’m missing something.

I’ve a dedicated server with plesk so the cronjob has not to be for user www-data as suggested in the manual.
Nextcloud is telling under which user the cronjob should be run so I’m taking this instead.

If I execute this in terminal

sudo -u bigdeal php /var/www/vhosts/big.deal/nextcloud.big.deal/cron.php 
sudo -u bigdeal /usr/bin/php /var/www/vhosts/big.deal/nextcloud.big.deal/cron.php 

everything works fine.

I created a crontab

crontab -u bigdeal -e

And

crontab -l

gives

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
*/15 * * * * php -f /var/www/vhosts/bigdeal/nextcloud.big.deal/cron.php #DOES NOT WORK
*/15 * * * * /usr/bin/php -f /var/www/vhosts/bigdeal/nextcloud.big.deal/cron.php #DOES NOT WORK
*/15 * * * * /bin/bash -c “php /var/www/vhosts/bigdeal/nextcloud.big.deal/cron.php” #DOES NOT WORK
*/15 * * * * bigdeal /bin/su -s /bin/sh -c “/usr/bin/php -f /var/www/vhosts/bigdeal/nextcloud.big.deal/cron.php” #DOES NOT WORK

With
sudo grep CRON /var/log/syslog

I get this output

Dec 20 23:54:01 server CRON[17092]: (bigdeal) CMD (php -f /var/www/vhosts/bigdeal/nextcloud.big.deal/cron.php)
Dec 20 23:55:01 server CRON[17157]: (bigdeal) CMD (/bin/sh -c “php -f /var/www/vhosts/bigdeal/nextcloud.big.deal/cron.php”)
Dec 20 23:55:01 server CRON[17159]: (bigdeal) CMD (/usr/bin/php -f /var/www/vhosts/bigdeal/nextcloud.big.deal/cron.php)
Dec 20 23:55:01 server CRON[17160]: (bigdeal) CMD (bigdeal /bin/su -s /bin/sh -c “/usr/bin/php -f /var/www/vhosts/bigdeal/nextcloud.big.deal/cron.php”)

This tells me, that those commands have been executed.
I read about problems with pathes, but since I use absolute pathes that should not be the case.
So:
What am I missing here?

Best regards

What user are you running you test cron jobs as? By default, sudo only allows root to run commands as another user (“bigdeal”). Put your cron jobs that require sudoing to another user into root’s crontab and see what happens.

Thanks for the reply.
I’m not really sure if I got what you mean. I added the cronjobs with

crontab -u bigdeal -e

same as crontab -e because bigdeal is the user I’m executing the command with

Now I added it with sudo crontab -e to root’s crontab. (hopefully that’s what you suggested). Than

sudo grep CRON /var/log/syslog

Gives me:

Dec 21 11:46:01 essen127 CRON[3141]: (bigdeal) CMD (/usr/bin/php -f /var/www/vhosts/bigdeal/nextcloud.big.deal/cron.php)
Dec 21 11:46:01 essen127 CRON[3142]: (root) CMD (/usr/bin/php -f /var/www/vhosts/bigdeal/nextcloud.big.deal/cron.php)

but Nextcloud tells me, that cron has not been executed.
So in my opinion same result as before.

Best regards

I you need to have the cron job run as the same user that runs the webserver. I don’t know what Linux flavor plesk uses, but under redhat the user “apache” needs the crontab.

Check to see who owns the nextcloud directory, that’s probably the user that needs the crontab entry.

Hi Scott,

the owner of the nextcloud directory is “bigdeal”. In the admin panel is also mentioned that the cronjob has to be run under this user. So I’m pretty sure that this should be the right user.

Best regards

I think by doing crontab -u bigdeal -e and sudo crontab -e you’ve pretty much done the same thing (presuming you’re logged in as ‘bigdeal’). Try logging in as root and doing crontab -e or doing sudo crontab -u root -e.

I only can tell you what the system gives me.

crontab -u bigdeal -l and crontab -l or logged in as root crontab -u bigdeal -l all print

SHELL=/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

          • /usr/bin/php -f /var/www/vhosts/bigdeal/nextcloud.big.deal/cron.php
            #* * * * * /bin/sh -c “php -f /var/www/vhosts/bigdeal/nextcloud.big.deal/cron.php”
            #* * * * * bigdeal /bin/su -s /bin/sh -c “/usr/bin/php -f /var/www/vhosts/bigdeal/nextcloud.big.deal/cron.php”

crontab -u root -e returns must be privileged to use -u
and
sudo crontab -u root -l
just like sudo crontab -l or logged in as root crontab -l
all give me this

#MAILTO=""
0 3 * * 7 /opt/psa/libexec/modules/watchdog/cp/clean-reports
0 1 * * 1 /opt/psa/libexec/modules/watchdog/cp/send-report weekly
10 1 * * * /opt/psa/libexec/modules/watchdog/cp/clean-sysstats
15 1 * * 1 /opt/psa/libexec/modules/watchdog/cp/pack-sysstats week
15 1 1 * * /opt/psa/libexec/modules/watchdog/cp/pack-sysstats month
15 1 1 * * /opt/psa/libexec/modules/watchdog/cp/pack-sysstats year
0 1 * * 1 /opt/psa/libexec/modules/watchdog/cp/secur-check
15 1 * * * /opt/psa/libexec/modules/watchdog/cp/pack-sysstats day
20 1 * * * /opt/psa/libexec/modules/watchdog/cp/clean-events

  •   *       *       *       *       /usr/bin/php -f /var/www/vhosts/bigdeal/nextcloud.big.deal/cron.php
    

MAILTO=""
0 0,4,8,12,16,20 * * * /opt/psa/admin/bin/php -dauto_prepend_file=sdk.php '/opt/psa/admin/plib/modules/wp-toolkit/scripts/maintenance.php’
0 0 * * * /opt/psa/admin/bin/php -dauto_prepend_file=sdk.php '/opt/psa/admin/plib/modules/wp-toolkit/scripts/instances-auto-update.php’
6 * * * * /opt/psa/admin/bin/php -dauto_prepend_file=sdk.php ‘/opt/psa/admin/plib/modules/letsencrypt/scripts/keep-secured.php’

After editing with sudo crontab -e the line

Dec 22 13:55:01 essen127 CRON[18300]: (root) CMD (/usr/bin/php -f /var/www/vhosts/bigdeal/nextcloud.big.deal/cron.php

was an additional output of sudo grep CRON /var/log/syslog
and after editing with crontab -e this line was added

Dec 22 13:55:01 essen127 CRON[18299]: (bigdeal) CMD (/usr/bin/php -f /var/www/vhosts/bigdeal/nextcloud.big.deal/cron.php)

All commands have been executed beeing logged in as user ‘bigdeal’.
So to me it seems like crontab -u bigdeal -e and sudo crontab -e are not the same thing.

System is an Ubuntu 16.04.3 LTS

Best regards

I did it allover again and I found my mistake. I did it by copy & paste but somehow I managed to make a typo anyway.
I’m very sorry for wasting your time!

Merry Christmas!