0

I am attempting to run two Drush commands from my crontab:

# m h  dom mon dow   command
*/2 * * * * drush -r /path -l https://www.domain.com/ cron
*/2 * * * * drush -r /path -l https://www.domain.com/ -u civicron civicrm-api job.execute

Both of these commands work when I run them manually on the server, however they do not appear to work through crontab, even though the log shows them running:

Apr 17 20:16:01 ip-000000000000 CRON[3736]: (ubuntu) CMD (drush -r /path -l https://www.domain.com/ -u civicron civicrm-api job.execute)
Apr 17 20:16:01 ip-000000000000 CRON[3737]: (ubuntu) CMD (drush -r /path -l https://www.domain.com/ cron)

Any suggestion as I cannot see why these would not be running?

1 Answer 1

4

I ran into a similar issue multiple times. I think in all cases cron was running a different version of php. To fix I ended up having to define my php path in my drush call:

*/5 * * * * /usr/local/bin/php /home/myuser/bin/drush elysia-cron run --root=/home/mysite/public_html --uri=www.mysite.com

Also, another thing that helped me debug the issue is by adding a log path > path/to/file.log like this and then looking at the exact error:

*/5 * * * * /usr/local/bin/php /home/myuser/bin/drush elysia-cron run --root=/home/mysite/public_html --uri=www.mysite.com > /home/mysite/cron.log 2>&1
1
  • I have also been caught by this, all I needed was the path to Drush, I did not have to worry about PHP - I just used 'which drush' for the user the crontab was set up for and substituted this path in the script. You can check it by creating a simple script that does a drush @your_alias status and redirect that to a log. Add it to cron to run every 5 mins and you can check all is OK. Just delete this task after you are happy
    – ChumKui
    Commented Aug 16, 2023 at 12:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.