I have the following Rule, but Version 1 of this rule always gives me a wrong result:
rule "test execute Command"
when
Item Dummy_3 changed to ON
then
// Version 1 - funktioniert nicht - ich kann den Grund nicht finden
var pingresult = executeCommandLine(Duration.ofSeconds(20),"/bin/ping","-c5","-W1", "192.168.178.75", ">", "/dev/null", "&&", "/bin/echo", 'online', "||", "/bin/echo", 'offline') // String in einer Variablen zwischenspeichern
logInfo("execute-Version 1","String - pingresult: {}", pingresult) // Log pingresult
// Version 2 - Der Shell-Befehl verpackt in einem Bash-Script, dann klappt's
pingresult = executeCommandLine(Duration.ofSeconds(10),"/bin/bash","/etc/openhab/scripts/ping_test.sh") // String in einer Variablen zwischenspeichern
logInfo("execute-Version 2","String - pingresult: {}", pingresult) // Log pingresult
// Version 3 - Shell-Kommando - einfach
pingresult = executeCommandLine(Duration.ofSeconds(2),"/bin/ls", "-alF") // String in einer Variablen zwischenspeichern
logInfo("execute-Version 3","String - pingresult: {}", pingresult) // Log pingresult
/* Das Bash-Script (ping_test.sh)- als Beispiel - Einfacher geht's mit dem Network-Binding ;)
#!/bin/bash
INPUT=$(/bin/ping -c5 -W1 192.168.178.99 >/dev/null && /bin/echo 'online' || /bin/echo 'offline')
echo $INPUT
*/
end
As a result I get in the log:
2021-06-27 13:30:37.266 [INFO ] [.core.model.script.execute-Version 1] - String - pingresult: ping: offline: Der Name oder der Dienst ist nicht bekannt
2021-06-27 13:30:41.404 [INFO ] [.core.model.script.execute-Version 2] - String - pingresult: online
2021-06-27 13:30:41.434 [INFO ] [.core.model.script.execute-Version 3] - String - pingresult: insgesamt 56
drwxrwxr-x+ 12 openhab openhab 4096 Jun 3 00:05 ./
drwxr-xr-x 31 root root 4096 Dez 26 2020 ../
drwxrwxr-x+ 5 openhab openhab 4096 Jun 25 13:50 cache/
drwx------+ 3 openhab openhab 4096 Dez 30 14:05 .config/
drwxrwxr-x+ 5 openhab openhab 4096 Jun 2 23:35 config/
drwxrwxr-x+ 3 openhab openhab 12288 Jun 2 23:33 etc/
drwxrwxr-x+ 3 openhab openhab 4096 Jan 26 00:23 jsondb/
drwxrwxr-x+ 2 openhab openhab 4096 Jun 3 00:05 kar/
drwxrwxr-x+ 2 openhab openhab 4096 Jun 5 22:40 .karaf/
drwxrwxr-x+ 5 openhab openhab 4096 Dez 26 2020 persistence/
drwxrwxr-x+ 2 openhab openhab 4096 Dez 26 2020 secrets/
drwxrwxr-x+ 11 openhab openhab 4096 Jun 25 13:53 tmp/
When I use the command in the console everything works fine:
hab3@hostHAB3:~ $ /bin/ping -c5 -W1 192.168.178.99 > /dev/null && /bin/echo 'online' || /bin/echo 'offline'
online
h
Does anyone know what I’m doing wrong in my command:
var pingresult = executeCommandLine(Duration.ofSeconds(20),"/bin/ping","-c5","-W1", "192.168.178.75", ">", "/dev/null", "&&", "/bin/echo", 'online', "||", "/bin/echo", 'offline')
Every help or hint is welcomed and thx in advance.
Cheers,
Peter