Answers: <p>I was able to get around this issue in a bit of a dodgy way by changing the command to:</p>
  
  <pre><code>/bin/bash -c "your-command-here | { ! grep '^'; }"
  </code></pre>
  
  <p>This pipes the output through <code>grep</code> and fails if there is any output at all, but <code>grep</code> still passes it through so you still get to see the output in Rundeck upon failure.</p>
  
  <p>One drawback is that I believe you lose any blank lines but we don't output any so no big deal for us, and it will tide us over until we can update the app to terminate with a proper exit code.</p>
  
Answers: CC BY-SA 4.0
Answers: 2018-12-06T08:31:48.553Z
Answers: 2018-12-06T08:31:48.553Z
Answers: Malvineous
Answers: <p>The way I could think of are:</p>
  
  <p>Writing your own plugin, from the notification plugin <a href="http://rundeck.org/docs/developer/notification-plugin.html#notification-handlers" rel="noreferrer">example page</a>, adapting the <a href="https://github.com/rundeck/rundeck/blob/master/examples/example-groovy-notification-plugins/MailNotificationPlugin.groovy" rel="noreferrer">example mail notification</a> code could be a way.</p>
  
  <p>Disabling success notifications in rundeck, and handle the success notification part in your script itself. This way that's your script responsibility to warn it did something in normal state and it's still rundeck responsibility to warn you the script failed.</p>
  
Answers: CC BY-SA 3.0
Answers: 2017-03-03T14:23:32.590Z
Answers: Thanks; when you get a feature wrapped up by the tool you have in front, it is so common sometimes to forget you can go for it directly....
Answers: ᴳᵁᴵᴰᴼ
Answers: CC BY-SA 3.0
Answers: 2017-03-03T14:01:42.267Z
Answers: 2017-03-03T14:01:42.267Z
Answers: Tensibai
Body: <p>We are using rundeck to scan logfiles for a service, and take action depending on what is found there. Basically, for each item found, for which a records does not exists, a git repository is initialized and a few rest endpoints are called, but that's not the point.</p>
  
  <p>We are setting up the job to run as scheduled, say every couple of hours, and to send notification on failure, and additionally to send notification on success only when at least one action has been taken (ie. the shell script in the task entered the loop at least once). The script is written so that it only emits output on stdout when items to be actioned are found.</p>
  
  <p>Is there a way in rundeck to trigger notification with this requirement? Or a way to script it without writing a plugin from scratch?</p>
  
  <p>One possible workaround would be to switch the failure notification trigger off, and make the script return non-zero in case of no items actioned, but I am not comfortable in doing that.</p>
  
Comments: CC BY-SA 3.0
Comments: 2017-03-03T13:17:28.600Z
Comments: Is the output really empty, or could it have some blanck lines or a carriage return ?
Comments: Tensibai
Comments: CC BY-SA 3.0
Comments: 2017-03-03T13:30:15.323Z
Comments: afaics it's empty, from a bash perspective; there is a single shell step with my script, not sure i rundeck would decorate it with output around
Comments: ᴳᵁᴵᴰᴼ
Comments: CC BY-SA 3.0
Comments: 2017-03-03T13:39:15.620Z
Comments: Would sending the notification from the script itself be an option ? And so rundeck only notify on failure and the script does its own "I did something" notification ?
Comments: Tensibai
Comments: CC BY-SA 3.0
Comments: 2017-03-03T13:52:57.180Z
Comments: That's actually a good idea!
Comments: ᴳᵁᴵᴰᴼ
Tags: <notifications><rundeck>
Title: How to send notification only in case of job output being non-empty
UserDisplayName: ᴳᵁᴵᴰᴼ
ThreadText: # How to send notification only in case of job output being non-empty
  
  (Asked by: username_0 on 2017-03-03)
  
  We are using rundeck to scan logfiles for a service, and take action depending on what is found there. Basically, for each item found, for which a records does not exists, a git repository is initialized and a few rest endpoints are called, but that's not the point.
  
  We are setting up the job to run as scheduled, say every couple of hours, and to send notification on failure, and additionally to send notification on success only when at least one action has been taken (ie. the shell script in the task entered the loop at least once). The script is written so that it only emits output on stdout when items to be actioned are found.
  
  Is there a way in rundeck to trigger notification with this requirement? Or a way to script it without writing a plugin from scratch?
  
  One possible workaround would be to switch the failure notification trigger off, and make the script return non-zero in case of no items actioned, but I am not comfortable in doing that.
  
  **Tags:** notifications, rundeck
  
  > **Comments:**
  > **username_1**: Is the output really empty, or could it have some blanck lines or a carriage return ?  
  > **username_0**: afaics it's empty, from a bash perspective; there is a single shell step with my script, not sure i rundeck would decorate it with output around  
  > **username_1**: Would sending the notification from the script itself be an option ? And so rundeck only notify on failure and the script does its own "I did something" notification ?  
  > **username_0**: That's actually a good idea!  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2017-03-03. Score: 7 | Accepted answer
  
  The way I could think of are:
  
  Writing your own plugin, from the notification plugin [example page](http://rundeck.org/docs/developer/notification-plugin.html#notification-handlers), adapting the [example mail notification](https://github.com/rundeck/rundeck/blob/master/examples/example-groovy-notification-plugins/MailNotificationPlugin.groovy) code could be a way.
  
  Disabling success notifications in rundeck, and handle the success notification part in your script itself. This way that's your script responsibility to warn it did something in normal state and it's still rundeck responsibility to warn you the script failed.
  
  > **Comments:**
  > **username_0**: Thanks; when you get a feature wrapped up by the tool you have in front, it is so common sometimes to forget you can go for it directly....  
  
  ---
  
  ### Answer by username_2 on 2018-12-06. Score: 1
  
  I was able to get around this issue in a bit of a dodgy way by changing the command to:
  
  ```
  /bin/bash -c "your-command-here | { ! grep '^'; }"
  
  ```
  
  This pipes the output through `grep` and fails if there is any output at all, but `grep` still passes it through so you still get to see the output in Rundeck upon failure.
  
  One drawback is that I believe you lose any blank lines but we don't output any so no big deal for us, and it will tide us over until we can update the app to terminate with a proper exit code.
  
  
  ---
  
  