Spocki990
(Clem Spocki)
September 11, 2023, 5:55pm
1
Hi,
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”
when
Item Nachtmodus changed to ON
then
executeCommandLine(“/etc/openhab2/scripts/changeBrightness.sh 20”)
end
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!
Wolfgang_S
(Wolfgang_S)
September 11, 2023, 6:03pm
2
Spocki990:
whats wrong?
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.
Spocki990
(Clem Spocki)
September 11, 2023, 6:13pm
3
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.
#!/bin/bash
echo $1 > /home/openhabian/Desktop/20
if i execute it in the terinal everything works fine.
Wolfgang_S
(Wolfgang_S)
September 11, 2023, 6:21pm
4
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.
e.g.
logError("foobar", "This is an error: {}", ScriptResponse )
Spocki990
(Clem Spocki)
September 11, 2023, 6:23pm
5
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