3

My cron job

usr/local/bin/wp --user=cronuser --url=https://mysite.org --path=/srv/www/mysite.org/public_html civicrm api job.execute auth=0

outputs:

Array
(
    [is_error] => 0
    [version] => 3
    [count] => 1
    [values] => 1
)

Is there a way to prevent this output without redirecting to /dev/null ? I'd like to get an email if there is a problem.

clarification: I'm really asking how to stop the output (if there are no errors) from the wp-cli command for scheduling civicrm jobs.

  • 3
    I'm voting to close this question as off-topic because this is a cron question, not a CiviCRM question. A good answer can be found here: stackoverflow.com/a/1396553/2832108. In short: redirect your stdout to /dev/null, but not stderr. – Jon G - Megaphone Tech Nov 1 '16 at 15:48
  • But is there a way to make this command run quiet if there are no errors. I'd like to see errors. It seems like there is some sort of debug mode turned on. And Is the output part of wp-cli or somehow from civicrm api? – onefiftyfour Nov 1 '16 at 19:39
  • @jon, IMO this is a CiviCRM issue and @onefiftyfour's instincts are right. UNIX tools are typically silent (or can be silent) in normal operation, and only generate output when there is an error state. CiviCRM lacks the --quiet switch which Xavier proposes below. See eg in ESR's "17 UNIX Rules" the Rule of Silence. CiviCRM not following this leads to many CiviCRM installs routing cron output to /dev/null, an antipattern that means they don't see error output from CiviCRM when necessary. – Chris Burgess Nov 4 '16 at 19:24
3

What I've done to fix this is create a bash script that executes the civicrm api command, captures the output to a variable, tests for the string [is_error] => 0, if there's no match, then it echos the output of the command.

Here's the script:

 #!/bin/bash

output=$(/usr/local/bin/wp --user=cronuser --url=https://mysite.org --path=/srv/www/mysite.org/public_html civicrm api job.execute auth=0)

### only print if error is not 0

if [[ $output != *"[is_error] => 0"* ]]
then
  echo "$output";
fi
1

So what you'd want is a "quiet" option that does only spit out a message if it's an error?

I'm not super sure what's the default on cron if there isn't any text, does it send an empty email?

it doesn't exist, but sounds like a good improvement. Do you have coding skills or resources to make it happen?

  • Cron only sends an email if there was output. Yes, a quiet option would be great. But I'm not sure if it's wp-cli creating the output or the civicrm command. – onefiftyfour Nov 2 '16 at 16:37
  • the output is from the api call, that generates an json in that case – Xavier Nov 2 '16 at 17:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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