OH 3 executeCommandLine not working

Hello, I am using OH3 and the new Action feature to call a script when a rule is executed.

The rule is:

rule "WeatherRequest"
    Item weatherRequestItem changed
    var String text = transform("JSONPATH", "$.status", weatherRequestItem.state.toString)

    logInfo("rhasspy_intent_weather", "Message: " + text)

    executeCommandLine("/etc/openhab/scripts/weather.sh", text)

The script is just writing the received argument to a File.

When I call the script by hand it works, but with executeCommandLine() it does not.
The Logs don’t show any error …

Im on that now for hours and really need help, thank you!

Please try

var ScriptResponse = executeCommandLine(Duration.ofSeconds(120),"/etc/openhab/scripts/weather.sh", text)

There is still no output of the script.

You might find out what the response was
logInfo("test", "Results " + ScriptResponse)

The response is:

/etc/openhab/scripts/weather.sh: line 2: /etc/openhab/scripts/debug.txt: Permission denied

I gave the user openhab all the rights over the txt-File … god I really don’t understand the right system of openhab :confused:

If no errors still there, you miss only to print the output

LogInfo(“test”, ScriptResponse )

AT the end

  • Does it work in case you place the file in /tmp/ ?
  • What is the content of weather.sh ?
  • what is the output of
    ls -ld /etc/openhab/scripts /etc/openhab/scripts/debug.txt

Has something else got your debug.txt file open i.e. you’re viewing it in an editor?

It has nothing to do with openHAB. Linux controls the permissions. Understanding Linux File Permissions - Linux.com. The only part OH has to play in this is the name of the user OH is running as is openhab. Beyond that it’s 100% operating system controlled.

If you were running on Windows you’d be dealing with Window’s file permissions which work completely differently.

But, without the information Wolfgang_S asked for we won’t really be able to help.


thanks for the inputs, it seems to work now after a complete power off and back on (reboots did not work either) … besides that, I changed nothing lol

I have no clue but let’s hope it keeps working O.o

Thanks to all!

Yes I already checked permissions, I know its Linux responsibility in the end but a lot of questions/answers talk about the weird openhab permission system and I dont understand why.

As a stated in the previous comment it works now after a full restart of the system … donk ask me why I have no clue lol

I read somewhere that openhab is overwriting some permissions at start is that true?
It might explain why it works now.

Most of the confusion is between openhabian (a tool to install and configure openhab, with some popular add-ons) and openHAB (the “product”).
Openhabian does things like setting permissions commonly needed.

I’d put money on your text file being open in some other application, perhaps even a previously spawned copy of your script.

There is nothing weird about permissions with openHAB. It operates like all other Linux programs when it comes to file permissions. It doesn’t do anything different or special or unusual.

What most people have a problem with is not understanding that everything that openHAB does is as the user openhab while everything they do from a command line is done as a different user (openhabian or pi or what ever their login happens to be) and that the two users are completely separate. Or if they do understand that, they don’t understand the implications of that.

tl;dr all of those questions and answers come from people who don’t know how permissions work in Linux. And because executeCommandLine and the Exec binding are asking Linux to run a command, there isn’t really anything that openHAB can do about that.

Yes it does overwrite some file permissions sometimes, but only those files in /etc/openhab and /var/lib/openhab and only when installing and/or upgrading. It doesn’t touch any other file in any other folder, including files in /tmp. You can run openhab-cli fix-permissions or something like that also to change the ownership and permissions on the files in those folders only. And that’s because the openhab user must have permission to read/write those files to operate.

openHABian also does some file permissions stuff but, as rossko57 said, openHABian isn’t openHAB. It’s completely separate.

Ultimately we’ll never know what the problem was because you never showed us the results of the ls -l command and you never showed us the contents of the script you were trying to run. From there we might have needed additional info like other processes running and the results of commands that tell you which processes have which files open which could have proven rossko57’s theory true or false. But since you never provided any of that information :man_shrugging: