Tutorial for EXEC add-on? Am I doing this right?

So, I’ve made some progress tinkering with running OH on a Raspberry Pi. I’ll move it on to a virtual machine later, once I develop my plan, but in the meantime I’m struggling with EXEC.

I’ve read many posts, but haven’t been able to find a beginner guide and want to confirm my understanding. The add-on is installed from apt-get, along with the rest of the software.

I have a basic script in /etc/openhab/configurations/scripts/test.sh the contents of which are
'echo "123"'

with ls -l reporting:
-rwxrwxrwx 1 openhab openhab 23 Jan 28 16:34 test.sh

I have an item that reads:
Number Exectest "Exx [%d]" { exec="<[/etc/openhab/configurations/scripts/test.sh:10000:REGEX((.*?))]" }

and a sitemap that contains
Text item=Exectest]

should I expect my sitemap to have a text item that reads ‘123’?
Where should I see errors? I nothing jumps out at me in /var/log/openhab/openhab.log

Usually by the time I type my post, I solve my own problem but that hasn’t happened so far…

Thanks!

Hi,
Is the bracket behind the Exectest a typo?
Cheers
Björn

It was, but it still doesn’t work…

For my old eyes, it looked like there is was a [ in the E…

hello,

I would try with a string item first. to be sure it’s not just a parsing problem. you did echo a string after all.

Thanks Sam - that does not appear to have helped, so I can rule that out.

This is working for me:

String conf_Show_Alarm "voila [%s]" {exec="<[python ./python/test.py:60000:REGEX((.*?))]" }

you did put org.openhab.binding.exec-1.8.0.jar in your addons folder?

I am not an expert on the Exec binding by any means but my advice is to use

val results = executeCommandLine("/etc/openhab/configruations/scripts/test.sh", 5000)
logInfo("Test", results)

in a rule while trying to debug Exec. This is the only way I’ve found to see the error that your script is producing and seeing what the script is producing can save hours of experimentation trying to figure out what, if anything the script is doing.

Once it works in a rule you can usually transfer the script back to an Exec bound Item, though I have personally left it in a rule so I can get a log of the results every time it runs which saves me some steps when trying to debug any problems that pop up.

One thing I will caution you about is there is some unexpected behavior in the way OH starts up. It runs a script that changes the permissions on all the files OH owns which will strip the execution permission off of your test.sh script. See this thread for details. An issue was created to fix this and I posted a work around in the mean time.

Sam - thanks. I was able to get that to work. I’m not sure what was different - it gave me a path error as the string value the first time. So, yay!

Rich - thanks for the detailed reply. More stuff for me to chew on as I learn how to configure this stuff. I’ll go check out the permissions post.

Cheers!

i think that by default, exec work in configurations directory.

so you can do: {exec="<[./scripts/test.sh:10000:REGEX((.*?))]"}