# executeCommandLine not working in OH4

**URL:** <https://community.openhab.org/t/executecommandline-not-working-in-oh4/149522>\
**Category:** Actions\
**Tags:** scripts, executecommandline, bash\
**Created:** [September 11, 2023, 5:55pm UTC](https://community.openhab.org/t/executecommandline-not-working-in-oh4/149522 "2023-09-11T17:55:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Spocki990](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@Spocki990](https://community.openhab.org/u/Spocki990)\
**Post date:** [September 11, 2023, 5:55pm UTC](https://community.openhab.org/t/executecommandline-not-working-in-oh4/149522/1 "2023-09-11T17:55:35Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Wolfgang\_S](https://community.openhab.org/user_avatar/community.openhab.org/wolfgang_s/32/52719_2.png) [@Wolfgang\_S](https://community.openhab.org/u/Wolfgang_S)\
**Post date:** [September 11, 2023, 6:03pm UTC](https://community.openhab.org/t/executecommandline-not-working-in-oh4/149522/2 "2023-09-11T18:03:06Z")

</div>

> [@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.

---

<div class="post-metadata">

**Author:** ![Spocki990](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@Spocki990](https://community.openhab.org/u/Spocki990)\
**Post date:** [September 11, 2023, 6:13pm UTC](https://community.openhab.org/t/executecommandline-not-working-in-oh4/149522/3 "2023-09-11T18:13:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Wolfgang\_S](https://community.openhab.org/user_avatar/community.openhab.org/wolfgang_s/32/52719_2.png) [@Wolfgang\_S](https://community.openhab.org/u/Wolfgang_S)\
**Post date:** [September 11, 2023, 6:21pm UTC](https://community.openhab.org/t/executecommandline-not-working-in-oh4/149522/4 "2023-09-11T18:21:48Z")

</div>

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

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

```

ScriptResponse then can be logged.  
e.g.

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

```

---

<div class="post-metadata">

**Author:** ![Spocki990](https://community.openhab.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@Spocki990](https://community.openhab.org/u/Spocki990)\
**Post date:** [September 11, 2023, 6:23pm UTC](https://community.openhab.org/t/executecommandline-not-working-in-oh4/149522/5 "2023-09-11T18:23:46Z")

</div>

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!!!
