[SOLVED] Problems with exec binding

first of all, this is my first day with openHAB…

I installed today the openHAB runtime core, the addons and the Designer.
I did the very good beginners guide from:

But I have no hardware to switch available, so i thought that I could emulate a switch with these two little programs:

First program “on.sh”
#!/bin/sh echo deleting off ; rm /home/USER/testfiles/off ; echo creating on ; touch /home/USER/testfiles/on ; echo exit

Second program “off.sh”
#!/bin/sh echo deleting on ; rm /home/mrstone/testfiles/on ; echo creating off ; touch /home/mrstone/testfiles/off ; echo exit

When I run this code in the terminal, everything is fine.

Then I added in the openHAB Designer the following line:
Switch Testswitch "Testswitch" (Testroom) {exec=">[ON:sh /home/USER/testfiles/on.sh] >[OFF:sh /home/USER/testfiles/off.sh]"}

Unfortunatly, nothing is happening when i press the switch in openHAB :frowning:

What is wrong?

Thx, mr_stone

Is openHAB running under the same user as you are at the prompt?

I use ubuntu.
I started openHAB as the normal user out of the shell, like it is in the beginners guide described.
I also tried to start it as root, but there is no difference in the behavior.

If you install openHAB using apt-get, by default the server is run as the openhab user, so whichever user runs the server, that user must have permission to run your scripts. Also, I’ve not needed to use sh in the command, and if the user that runs the server is not setup to login, it may not have paths set to find sh on the path.

First I suggest to add #!/bin/sh at the very Beginning of the two scripts.
Second, have you used chmod 755 to the Scripts? Maybe they are not executable.
Third, are you sure that you have added the exec-binding to addons?

1 Like

Yes, I installed it using apt-get, but neither in the /etc/passwd is a user “openhab” nor i can give the user the permission to run scripts.
Unfortunatly it changed nothing, when I deleted the sh in front of the path :disappointed_relieved:

First, of course, I am going to add #!/bin/sh :slightly_smiling:
Second, yes, the scripts are executable. I have tested it in the terminal.
Third, the file “org.openhab.binding.exec-1.8.1.jar” is in the folder “addons”.

That’s quite concerning. I was unaware that an install could complete quietly without creating an openhab user. @theo, is this normal?

Hi @ all,
Due to the reason that there is no user “openhab”,
I just added it myself with:

sudo adduser --no-create-home --system openhab

Now I have the line


in the /etc/passwd, without any change of my problem.

My next idea was, to find out the user who is actually running openHAB.
So I looked for the processes with

ps -ef | grep open.

There is just the grep process itself running… I am confused! :disappointed_relieved:

If you have followed the guide in your first post (https://openhabdoc.readthedocs.org/de/latest/Raspberry/) you don’t have an apt-get install (except “apt-get update” and “apt-get upgrade”, which updates your operating system but does not install openhab), you have a manual install!
That would explain why you have no openhab user.
If this is the case, you should uninstall openhab by simply removing all the copied files (presumably
/opt/openhab/) and then follow the official guide here for an apt-get install …

1 Like

Thank you @sihui! I’ve got a new laptop and I did many installations the last week. It really looks like I didn’t do the installation via apt-get.
A classic PEBCAK form my side! :grin:

I removed the hole manual installation and did it this time using apt-get. This time for real! :yum:
Now I’ve got the openhab user automatically and
ps -ef | grep open
finds two openhab processes!

But, unfortunately my problem still exists.

To check the permissions I did:
namei -l /home/USER/testfiles/on.sh

It replies:

drwxr-xr-x root root / drwxr-xr-x root root home drwxr-xr-x USER USER USER drwxrwxr-x USER USER testfiles -rwxrwxrwx USER USER on.sh

So there shouldn’t be a problem with the permissions.


Openhab now runs under user “openhab” (at least it should :slightly_smiling: )
So I think your files also need to be executed under user “openhab”, as @watou already suggested in an earlier post.
Also make sure what @Udo_Hartmann told you regarding permissions (chmod …)

Thank you @sihui for your your quick reply, but I’m confused now. :confused:

Yes, I checked that with ps -ef | grep open

I checked the permissions with:
namei -l /home/USER/testfiles/on.sh

It replies:

drwxr-xr-x root root / drwxr-xr-x root root home drwxr-xr-x USER USER USER drwxrwxr-x USER USER testfiles -rwxrwxrwx USER USER on.sh

Maybe I’m simply wrong, but I tought that the last “x” in every line says that every user can run that script, also the openhab user.

In the meanwhile I checked also the openhab.log after switching, there are these two lines:

2016-02-06 16:12:08.217 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine 'sh /home/USER/testfiles/on.sh' 2016-02-06 16:12:20.250 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine 'sh /home/USER/testfiles/off.sh'

If there is a permission error, would there be an error prompt in the log file?

My linux skills are not experienced enough to help you out here, but what confuses me is:

drwxrwxr-x USER USER testfiles

Did you just replace your real user “openhab” with the characters “USER” to not show it to the public (always a good idea) or do you run openhab under user “USER”???

Edit: if you are using “USER” to run openhab, you need to change the file /etc/default/openhab, replace USER_AND_GROUP=openhab:openhab with the appropriate user (but I don’t know what else has to be changed to make this work …)

I replaced my own username with “USER” to not show it to the public.

In the reply of the command namei or also ls -l:

drwxr-xr-x USER USER restfiles

the first “USER” means the owning user and the second USER means the owning group.
Here is a good explanation in the second post about that.

Does anyone know if there is a permission error, would there be an error prompt in the log file?

To exclude that the problem has something to do with executing a shell script I changed my method to emulate the switch.

Now the two commands are:
mkdir /home/USER/testfiles/on
rmdir /home/USER/testfiles/on

The line in the .items file is now:
Switch Testswitch "Testswitch" (Testroom) {exec=">[ON:mkdir /home/USER/testfiles/on] >[OFF:rmdir /home/USER/testfiles/on]"}

The log file reports:

2016-02-06 18:59:02.286 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine 'mkdir /home/USER/testfiles/on' 2016-02-06 18:59:24.341 [INFO ] [.o.b.exec.internal.ExecBinding] - executed commandLine 'rmdir /home/USER/testfiles/on'

Also the wiki hint to use the special delimiter @@ to split command line parameters makes no change.

In the post is a similar problem discussed and for the author of this post, the given solution worked.

I tried to change the rights in the /etc/default/openhab also to root:root but after that, the openHAB server doesn’t start.

sudo systemctl status openhab says:

Feb 06 19:54:50 USER-COMPUTER openhab.sh[11046]: <title>Invalid Configuration Location</title>The configuration area at '/var/lib/op...option.

If openHAB runs under the user openhab, and this should be the case, you need to create and remove the directory at a place, where the openhab user has full rights.

  1. you should create a directory
    sudo mkdir /tmp/openhab and grant full access with
    sudo chown openhab: /tmp/openhab
  2. you should use the full path, [ON:/bin/mkdir /tmp/openhab/on]

To create a file instead of a directory, you could use /bin/touch and /bin/rm, or even easier, use [ON:/bin/echo on >> /tmp/openhab/myswitch].

To see instantly, if this works, once the file /tmp/openhab/myswitch exists, you can use
tail -f /tmp/openhab/myswitch to see every switching just in time.

1 Like

Thank you very much @Udo_Hartmann!!! You gave me the right hint!

My failure was, that my whole attention was at the permissions of the user “openhab” to execute the comands! But the user “openhab” needs also the right to write the file into the directory… :wink:

For me, it was very helpful to log in as the user openhab itself:

sudo sh - openhab

To do that, it is necessary to add the bash into the openhab line in /etc/passwd:

openhab:x:120:130:openHAB runtime user,,,:/var/lib/openhab:/bin/bash

When you are logged in as openhab, you get the error promts. These prompts are very helpful. Unfotunately, you cannot find them in the /var/log/openhab/openhab.log file.

Ok, here is the solution:

I changed the location of the shell scipts to


I changed the ownership of the scripts:

sudo chown openhab on.sh
sudo chown openhab off.sh
sudo chgrp openhab on.sh
sudo chgrp openhab off.sh

I modified the paths in the scrips:

#!/bin/sh echo deleting off ; rm /etc/openhab/configurations/scripts/testfiles/off ; echo creating on ; touch /etc/openhab/configurations/scripts/testfiles/on ; echo exit

#!/bin/sh echo deleting on ; rm /etc/openhab/configurations/scripts/testfiles/on ; echo creating off ; touch /etc/openhab/configurations/scripts/testfiles/off ; echo exit

With these changes, the exec binding works fine! :grin:

Thank you very much for your help!
My next steps will be, to install openHAB on a raspberry pi which is currently running the fhem homeautomation software.

Hi mr_stone. Let me know how you are getting on. I have OpenHAB 2.0 installed and I have shell scripts to read One Wire values from the filesystem. The script works just fine from the command line, but not from OpenHAB. I don’t see the exec binding in openhab 2, I wonder if it is built in or not. Anyway, still could not get it working so far.

You might have to copy the binding’s JAR file to your addons folder.

Hi @Csongor_Varga, how are things going?
Have you solved your problem so far?