Answers.Body: <p>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.</p>
  
  <p>Here's the script:</p>
  
  <pre><code> #!/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] =&gt; 0"* ]]
  then
    echo "$output";
  fi
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2020-04-21T14:39:02.710Z
Answers.Text: We've expanded on very good idea into [civi_api_trap_errors.sh](https://github.com/twomice/misc/blob/master/civicrm/civi_api_trap_errors.sh), to which we pipe all civicrm cron job output, like so:
  */14 * * * * /usr/bin/php /usr/local/bin/cv api job.execute --user=civicrm_cron --cwd=/var/www/domains/example.org/html 2>&1 | /usr/local/bin/civi_api_trap_errors.sh;
Answers.UserDisplayName: TwoMice
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-03T16:15:08.723Z
Answers.LastActivityDate: 2016-11-03T16:15:08.723Z
Answers.UserDisplayName: onefiftyfour
Answers.Body: <p>So what you'd want is a "quiet" option that does only spit out a message if it's an error?</p>
  
  <p>I'm not super sure what's the default on cron if there isn't any text, does it send an empty email?</p>
  
  <p>it doesn't exist, but sounds like a good improvement. Do you have coding skills or resources to make it happen?</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-02T16:37:23.500Z
Answers.Text: 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.
Answers.UserDisplayName: onefiftyfour
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-02T17:13:23.497Z
Answers.Text: the output is from the api call, that generates an json in that case
Answers.UserDisplayName: Xavier
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-11-02T08:25:47.233Z
Answers.LastActivityDate: 2016-11-02T08:25:47.233Z
Answers.UserDisplayName: Xavier
Body: <p>My cron job </p>
  
  <pre><code>usr/local/bin/wp --user=cronuser --url=https://mysite.org --path=/srv/www/mysite.org/public_html civicrm api job.execute auth=0
  </code></pre>
  
  <p>outputs:</p>
  
  <pre><code>Array
  (
      [is_error] =&gt; 0
      [version] =&gt; 3
      [count] =&gt; 1
      [values] =&gt; 1
  )
  </code></pre>
  
  <p>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.</p>
  
  <p>clarification: I'm really asking how to stop the output (if there are no errors) from the wp-cli command for scheduling civicrm jobs.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-01T15:48:53.040Z
Comments.Text: 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: http://stackoverflow.com/a/1396553/2832108.  In short: redirect your stdout to /dev/null, but not stderr.
Comments.UserDisplayName: Jon G - Megaphone Tech
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-01T19:39:56.103Z
Comments.Text: 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?
Comments.UserDisplayName: onefiftyfour
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-11-04T19:24:31.463Z
Comments.Text: @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"](https://en.wikipedia.org/wiki/Unix_philosophy#Eric_Raymond.E2.80.99s_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.
Comments.UserDisplayName: Chris Burgess
Tags: <cron>
Title: To prevent cron emails do I need to redirect output to /dev/null?
ThreadText: # To prevent cron emails do I need to redirect output to /dev/null?
  
  (Asked by: username_0 on 2016-11-01)
  
  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.
  
  **Tags:** cron
  
  > **Comments:**
  > **username_1**: 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: http://stackoverflow.com/a/1396553/2832108.  In short: redirect your stdout to /dev/null, but not stderr.  
  > **username_0**: 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?  
  > **username_2**: @jon, IMO this is a CiviCRM issue and @username_0'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 username_4 proposes below. See eg in [ESR's "17 UNIX Rules"](https://en.wikipedia.org/wiki/Unix_philosophy#Eric_Raymond.E2.80.99s_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.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_0 on 2016-11-03. Score: 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
  
  > **Comments:**
  > **username_3**: We've expanded on very good idea into [civi_api_trap_errors.sh](https://github.com/twomice/misc/blob/master/civicrm/civi_api_trap_errors.sh), to which we pipe all civicrm cron job output, like so: */14 * * * * /usr/bin/php /usr/local/bin/cv api job.execute --user=civicrm_cron --cwd=/var/www/domains/example.org/html 2>&1 | /usr/local/bin/civi_api_trap_errors.sh;  
  
  ---
  
  ### Answer by username_4 on 2016-11-02. Score: 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?
  
  > **Comments:**
  > **username_0**: 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.  
  > **username_4**: the output is from the api call, that generates an json in that case  
  
  ---
  
  