OpenHab 3 - Failed to execute commandLine '[/etc/openhab/scripts/resetmodbus.sh]' in rule

Hello,
I have rule, that executes command line when item change state:

script is DSL rule:

executeCommandLine(Duration.ofSeconds(6),"/etc/openhab/scripts/resetmodbus.sh")

Why it is not working??

2020-12-07 00:27:16.937 [WARN ] [rg.openhab.core.io.net.exec.ExecUtil] - Failed to execute commandLine '[/etc/openhab/scripts/resetmodbus.sh]'

This .sh file works from ssh.

chmods are ok?

[00:33:24] openhabian@openHABianDevice:/etc/openhab/scripts$ ls -la
razem 24
drwxrwxr-x+  2 openhab    openhab 4096 gru  6 11:22 .
drwxrwxr-x+ 15 openhab    openhab 4096 lis 12 00:16 ..
-rw-rw-r--   1 openhab    openhab  236 paź  6 01:31 readme.txt
-rw-rw-r--   1 openhabian openhab  133 lis 23 00:53 resetmihome.sh
-rw-rw-r--   1 openhabian openhab  133 gru  6 00:33 resetmodbus.sh

No.

The scripts do not have any execute permissions

Not without execute permissions, it doesn’t. I guarantee /etc/openhab/scripts/resetmodbus.sh does not work from an ssh session due to no execute permissions.

sh /etc/openhab/scripts/resetmodbus.sh wiould work, bypassing the permissions issue so that is not a valid test.

Right now this is a Linux issue, not an openHAB one.

1 Like

OK I added chmod +x and now I get

2020-12-07 00:58:04.036 [WARN ] [shd.server.session.ServerSessionImpl] - exceptionCaught(ServerSessionImpl[null@/127.0.0.1:46000])[state=Opened] IOException: Połączenie zerwane przez drugą stronę

I need to add logentry to this rule to check what is going on.

I think that translates to “Connection broken by the other party” I am not sure any additional logging wold help, but you made some progress.

yes it is:
[shd.server.session.ServerSessionImpl] - exceptionCaught(ServerSessionImpl[null@/127.0.0.1:40886])[state=Opened] IOException: Connection reset by peer

I add chmod, changed chown to openhab:openhabian and still same result.

Is there a firewall in the network data path?

is that syntax correct ?
According to Actions | openHAB it is

executeCommandLine(String commandLine, int timeout)

No there are no firewalls? It has to execute command on rpi on which OH is installed.

this is actual syntax. That from Your link is old one.

1 Like

This thread Rule issue explicitly uses a shell as a parameter to execute the script. Does that work ?

nothing works…

Ok, so I managed to work it out.

It was only chmod and chown problems.
Now everything is working properly.

Add something like

/bin/date >> /tmp/test.txt
/bin/echo "this line was executed" >> /tmp/test.txt

after the line with the shebang in the script file.
In case you see the result of the call to date and echo in /tmp/test.txt file we see that the shell script starts to execute. In case this is not visible in the test.txt file the shell script is not executed.
Or have you already done a similar test ?

Not sure if OH3 checks the ownershop of the script that is to be executed. Your script is owned by user openhabian and not by user openhab. I understand that you added x permission for u, g, o. In case OH3 checks the ownership it might be the case that the execution is not allowed if it is owned by an other user.

EDIT: just saw that you had the same idea and I just was typing too slow

1 Like

@Kamil_Matuszczak I have exactly the same problem. Can you tell me the permissions you used?

Files to be executed must be readable and executable for user openhab.
For output to be stored the directory / file needs to be writeable for user openhab.

That’s what I thought.
But I have this
-rwxrwxr-x 1 openhab openhabian 181 Jan 12 09:03 opnsense.sh
and it’s not working.
this is what I call:
executeCommandLine(Duration.ofSeconds(10), “sudo /etc/openhab/scripts/opnsense.sh”)
Everything was working correctly before the update to OH3.

According to Actions | openHAB arguments should be separated so please try if

executeCommandLine(Duration.ofSeconds(10), "sudo", "/etc/openhab/scripts/opnsense.sh")

works. Pay attention to the double quotes in case you copy code from the forum to your rule. It could be that instead of the ASCII double quotes a set of utf-8 double quotes are used.

Is the openhab user member of the sudo group on your system?
I think that is not the case for the defualt installation.

Permissions that are shown are ok.

Shebang ( #! ) in the script defines the interpreter to be used ?

Does the script just execute an action or do you also expect to get output back from the script ( may be into a variable in OH ) ?

The problem was the separation of arguments. Thanks a lot.

2 Likes