executeCommandLine not working in OH4


i want to update my OH2 running on a Raspi in my camper to OH4 and have some issues with the executeCommandLine command. in OH2 it worked like this…

rule “Nachtmodus”
Item Nachtmodus changed to ON
executeCommandLine(“/etc/openhab2/scripts/changeBrightness.sh 20”)

the script changes a value in a file

for OH4 i know, that i have to change the command. it looks now like this…

executeCommandLine(Duration.ofSeconds(5), “changeBrightness.sh”, “20”)

i copied the script in /usr/local/bin, so its executable from everywehre without “bash”, and exery user is allowed to execute it.

whats wrong?

thanks in advance!

Are you sure that the PATH variable for the openhab user is containing /usr/local/bin ?
It doesn’t hurt to use the full path.
Use the return value of the function executeCommandLine and log it to openhab.log then you get an idea about what is going wrong.

even with path ist not working.

executeCommandLine(Duration.ofSeconds(5), “/usr/local/bin/changeBrightness.sh”, “20”)

how can i log? i dont get an return value, i just want to overwrite a value in a file.
the skript looks like this.

echo $1 > /home/openhabian/Desktop/20

if i execute it in the terinal everything works fine.

User openhab has enough privileges to write to that file ?
For a trial put that file on /tmp and give it 777 permission.

var ScriptResponse = executeCommandLine(Duration.ofSeconds(60), "path/to/my/script.sh");

ScriptResponse then can be logged.

logError("foobar", "This is an error: {}", ScriptResponse )

Sorry, now i got it with the logging.

2023-09-11 20:20:59.736 [INFO ] [penhab.core.model.script.Exec Result] - /usr/local/bin/changeBrightness.sh: line 3: /home/openhabian/Desktop/20: Permission denied

the file i wanted to change was not allowed to change.

Thanks for the hint with th log!!!

1 Like