From b0386c43f4bdd3fa89e1c8994451fb5c353817e9 Mon Sep 17 00:00:00 2001 From: Jerome Luckenbach Date: Thu, 24 Dec 2020 09:52:32 +0100 Subject: [PATCH] Improved Exec Action explanation with examples. (#1369) * Improved Exec Action explanation with examples. Signed-off-by: Jerome Luckenbach * Fixed method typo to ofSeconds(). Added java doc link for other possible units. Signed-off-by: Jerome Luckenbach --- addons/actions.md | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/addons/actions.md b/addons/actions.md index 2c3276fc1..f7d1cb2d5 100644 --- a/addons/actions.md +++ b/addons/actions.md @@ -57,8 +57,36 @@ One can configure whether specific log entries are logged out and where they get ### Exec Actions +You have different options to execute a command through an action. + - `executeCommandLine(String commandLine)`: Executes a command on the command line without waiting for the command to complete -- `executeCommandLine(Duration.fromSeconds(timeout), String commandLine)`: Executes a command on the command and waits `timeout` seconds for the command to complete, returning the output from the command as a String +For example you could run `executeCommandLine("path/to/my/script.sh")` which then would be executed and the rule would continue processing. + +- `executeCommandLine(Duration.ofSeconds(timeout), String commandLine)`: Executes a command on the command and waits `timeout` seconds for the command to complete, returning the output from the command as a String +For example you could run `var ScriptResponse = executeCommandLine(Duration.ofSeconds(60), "path/to/my/script.sh");` would get executed and wait 1 minute for the output to be responded back and write it into the `ScriptResponse` variable. + +Other Durations than `ofSeconds` units are possible too. +Check out the [Java Documentation](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/time/Duration.html?is-external=true) for possible units. + +#### Scripts with parameters + +Let's assume that your `path/to/my/script.sh`-Script needs two item states to process them with some calculation. +In console you would call it like + +```text +path/to/my/script.sh itemState1 itemState2 +``` + +To solve this constellation within a rule you have to add one argument per script parameter to the function. +The script above would be configured like shown below. + +```text +// When you are not interested in the script output +executeCommandLine("path/to/my/script.sh", itemState1, itemState2); + +// When you need the output in your further rule processing +var ScriptResponse = executeCommandLine(Duration.ofSeconds(60), "path/to/my/script.sh", itemState1, itemState2); +``` ### HTTP Actions