[Solved by workaround] openHAB 1.8.3: Problem with EXEC command

Hello,
I seem to have a general problem when trying to execute a shell command (I’m running openHAB on a RPi2/Debian installation). Sure it’s a problem with the peristence definition, but I don’t know how to solve. I’m working on this issue for three days now :frowning:

Here’s the error:
2016-09-14 08:15:00.010 [ERROR] [.o.p.exec.internal.ExecService] - Could not execute command [null]
java.lang.NullPointerException: null
at java.util.regex.Matcher.getTextLength(Matcher.java:1283) ~[na:1.8.0_65]
at java.util.regex.Matcher.reset(Matcher.java:309) ~[na:1.8.0_65]
at java.util.regex.Matcher.(Matcher.java:229) ~[na:1.8.0_65]
at java.util.regex.Pattern.matcher(Pattern.java:1093) ~[na:1.8.0_65]
at java.util.Formatter.parse(Formatter.java:2547) ~[na:1.8.0_65]
at java.util.Formatter.format(Formatter.java:2501) ~[na:1.8.0_65]
at java.util.Formatter.format(Formatter.java:2455) ~[na:1.8.0_65]
at java.lang.String.format(String.java:2940) ~[na:1.8.0_65]
at org.openhab.persistence.exec.internal.ExecService.formatAlias(ExecService.java:113) ~[na:na]
at org.openhab.persistence.exec.internal.ExecService.store(ExecService.java:49) ~[na:na]
at org.openhab.core.persistence.internal.PersistItemsJob.execute(PersistItemsJob.java:55) [org.openhab.core.persistence_1.8.3.jar:na]
at org.quartz.core.JobRunShell.run(JobRunShell.java:213) [quartz-all-2.1.7.jar:na]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557) [quartz-all-2.1.7.jar:na]

And here’s what I have defined:
ITEM:

String LgTvBetrieb        "TV Betrieb [%s]"      <socket>        { exec="<[/opt/openhab/configurations/scripts/ping.sh 192.168.1.99:60000:REGEX((.*?))]" }

Persistence:

// persistence strategies have a name and a definition and are referred to in the "Items" section
Strategies {
    everyMinute   : "0 * * * * ?"
}
Items {
    LgTvBetrieb: strategy=everyMinute
}

The script returns the text “ON” or “OFF”; it seems to be a problem with the java formatter but I didn’t find a proper example to correct my persistence for this case.

Thank you for your support!

Cheers,
Boby

I don’t see why this should be persistence related.

You should try:

exec="<[/opt/openhab/configurations/scripts/ping.sh@@192.168.1.99:60000:REGEX((.*?))]"

Furthermore, you should check if the openhab user is allowed to execute ping.sh (file permissions). Or is OH running as root?

Stefan, thank you - I’ll try it in the evening when I’m back home.
On my RPi2, everything runs as root since it’s a dedicated hardware for openHAb only.

Best regards,
Robert

Nope, unfortunately still the same result:

20:49:00.014 [ERROR] [.o.p.exec.internal.ExecService:84 ] - Could not execute command [null]
java.lang.NullPointerException: null
at java.util.regex.Matcher.getTextLength(Matcher.java:1283) ~[na:1.8.0_65]
at java.util.regex.Matcher.reset(Matcher.java:309) ~[na:1.8.0_65]
at java.util.regex.Matcher.(Matcher.java:229) ~[na:1.8.0_65]
at java.util.regex.Pattern.matcher(Pattern.java:1093) ~[na:1.8.0_65]
at java.util.Formatter.parse(Formatter.java:2547) ~[na:1.8.0_65]
at java.util.Formatter.format(Formatter.java:2501) ~[na:1.8.0_65]
at java.util.Formatter.format(Formatter.java:2455) ~[na:1.8.0_65]
at java.lang.String.format(String.java:2940) ~[na:1.8.0_65]
at org.openhab.persistence.exec.internal.ExecService.formatAlias(ExecService.java:113) ~[na:na]
at org.openhab.persistence.exec.internal.ExecService.store(ExecService.java:49) ~[na:na]
at org.openhab.core.persistence.internal.PersistItemsJob.execute(PersistItemsJob.java:55) [org.openhab.core.persistence_1.8.3.jar:na]
at org.quartz.core.JobRunShell.run(JobRunShell.java:213) [quartz-all-2.1.7.jar:na]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:557) [quartz-all-2.1.7.jar:na]

Best regards,
Boby

Could you probably modify your script so that you did not have to hand over your ip address to the script?

Does the script work when you execute it directly in a shell?

I have nearly the same exec expression and it runs without any problems:

{ exec="<[/scripts/iphonedetect.sh@@192.168.178.35@@11-22-33-44-55-66:60000:REGEX((.*?))]" }
(second part of the numbers is the mac address of my phone, I have changed it here)

Unfortunately, it didn’t help. Could you show me your persistence definition for your exec item?
Maybe there’s my problem…

I’m wondering now, because I renamed the script from “ping.sh” to “ping_lgtv.sh” and hard-coded the ip address into the script, so no parameter have to be handed over and there are no spaces anymore in the call:

String LgTvBetrieb        "TV Betrieb [%s]"      <socket>        { exec="<[/etc/openhab/configurations/scripts/ping_lgtv.sh:60000:REGEX((.*?))]" }

But still, I get exactly the same error - and nowhere is mentioned the name of the called script.
Maybe not the hand-back of the value fails; maybe the exec command itself because it believes it does not get a script name?

Thanks,
Boby

P.S.: I also did a complete fresh install of openHAB, but this time using apt-get (first installation was done manually in different folders). Every else works again, but not the EXEC binding :open_mouth:

I have no dedicated persistence for my exec item. It is persisted through my “general” mapdb persistence:

Strategies {
default = everyUpdate
}
Items {
// persist all items on every change and restore them from the db at startup
* : strategy = everyChange, restoreOnStartup
}

Maybe you’ll make a test and make another item with another exec command (maybe taken from the wiki or any tutorial) to see if the binding itself is the problem or your constellation with ping.sh.

And you should set the log level to DEBUG (if not already done so). Then you can see if the script is really executed.

You could try to use the script from a rule, using the action

rule "test exec binding"
when
    Time cron "0 * * * * ?"
then
    var String myVar=executeCommandLine("/opt/openhab/configurations/scripts/ping.sh@@192.168.1.99:60000:REGEX((.*?))")
    logInfo("exec","myVar = {}",myVar)
end

This way, you can see, if any errors occur.

By the way: Do you know the networkhealth binding? This would do almost the same but without struggling with scripts :wink:

Udo, thank you very much! No, I didn’t know the networkhealth binding which seems to cover exacly my current need.
Regarding the exec binding: It’s fun, because using rules, I can start every single script or command; I even have a “reboot raspberry” and “restart openhab service” button on my sitemap - and they work as a rule.

But the exec binding itself is still not working, but I don’t want to spend too much time on this issues since there is more than one working workaround - so thank you all for your contribution & your support.

Bye,
Boby