0

The facility to email reports using scheduled tasks is good and works. However we'd like to email a report at 5pm each day. Having started this task to run after 4:59 on a certain day it is now slipping every few days to a later time. We run cron every 15 minutes so a week ago it ran at 5pm, and it's now slipped to 5:30pm in one week. Is there a way to email a report at a fixed time each day?- A few minutes difference doesn't matter. I don't think 'Scheduled Reminders' can do this as it needs some kind of trigger.

1 Answer 1

2

CronPlus Extension

Take a look at the CronPlus extension to execute tasks in more accurate way and this SE question.

Alternatively, you could setup a cron task and script to do this like below:

Cron task

0 17 * * * su www-data -s /bin/bash -c "/home/example/cronscripts/send_daily_reports.sh"

The send_daily_reports.sh file.

# 7 A Report title
# 8 Another Report title
for rept in 7 8
do
 
    /usr/bin/php /usr/local/bin/wp --user=civicron --url=https://example.org --require=/var/www/example/wp-content/plugins/civicrm/wp-cli/civicrm.php --path=/var/www/example civicrm api Job.mail_report instanceId=${rept} format=csv --allow-root  > /dev/null 2>&1

done

One benefit of using the CLI cron task approach is that in the scheduled jobs UI, my experience is multiple reports cannot send at the same time, even if you have multiple jobs created.

Update 3/20/2024: As of 5.71.1 and likely much earlier, creating multiple "mail_report" jobs works OK now.

3
  • Thanks, Andy. I thought I'd heard of this problem before but oddly searching didn't find anything.
    – Andy Clark
    May 31, 2023 at 7:13
  • I was too hasty to check that as an answer - the extension has an issue which seems to be terminal at present.
    – Andy Clark
    May 31, 2023 at 8:06
  • Noting the issue with detailed logging for plus: lab.civicrm.org/extensions/cronplus/-/issues/8#note_91064. I added an alternative method with a cron task at CLI.
    – Andy Burns
    Jun 24, 2023 at 5:47

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.