Hi,
currently I am migration from the exec 1 to the exec 2 binding.
I have a shell script, which outputs a single number. With the exec 1 binding I used the following item to retrieve this number:
//Number Network_TCP_Count "TCP Con. Count: [%d]" <chart> (gNetwork, gNetworkMonitor) { exec="<[/usr/local/bin/netmonitor.sh --tcpcount:1800000:REGEX((.*?))]", expire="1h10m, -1" }
This worked without problems
I converted this to the following Thing and item:
Thing exec:command:netmonitor [ command="/usr/local/bin/netmonitor.sh --tcpcount", interval=1800, timeout=30, autorun=false, transform="REGEX(((.*?))" ]
Number Network_TCP_Count_Str "TCP Con. Count: [%s]" <chart> { channel="exec:command:netmonitor:output" }
With this I noticed several problems:
-
When the bash script does not print a newline character after the number the item Network_TCP_Count_Str will be empty, that of course is not a real problem.
-
There is a lot of additional text going into the item. When I print its value, I get:
232
(Es konnten nicht alle Prozesse identifiziert werden; Informationen ĂĽber
nicht-eigene Processe werden nicht angezeigt; Root kann sie anzeigen.)
(Es konnten nicht alle Prozesse identifiziert werden; Informationen ĂĽber
nicht-eigene Processe werden nicht angezeigt; Root kann sie anzeigen.)
“232” is the number I am interested in. The additional text roughly translates into “Not all process could be identified, information about none own processes are not shown, root can show them”.
I am using openhab on Linux and openhab is executed as user “openhab”, so the warning makes sense but I do not know, why the text is inserted into the output, it is not printed by my script.
As a workaround I tried to change the regex to only fetch the number, I tried several variants which, according to reges101 should be fine:
transform="REGEX((\\d+))"
transform="REGEX(([0-9]+))"
transform="REGEX((\\d+?))"
transform="REGEX(([0-9]+?))"
(I am not sure why the ? is needed in the original regex, but without the resulting string is empty)
The ultimate goal is to convert the result into a number, as far as I understand it I will need a rule for that. As a workaround I will parse the string in this rule, but there must be a more elegant resolution to the problem?
Thanks for your help!
Juelicher