Rules-execute command

Everyone’s fav topic LOL

This works fine from the CLI; when i try to run it via openhab, It doesn’t do anything.
executeCommandLine(“/etc/openhab2/LR-TVPower.sh”)

In CLI if i run ./LR-TVPower.sh it works
In CLI If i run sudo -u openhab ./LR-TVPower.sh it works
I’ve given openhab permission to that file
I’ve tried executeCommandLine(“sudo /etc/openhab2/LR-TVPower.sh”)
I’ve tried executeCommandLine(“sudo bash /etc/openhab2/LR-TVPower.sh”)
I’ve tried executeCommandLine(“bash /etc/openhab2/LR-TVPower.sh”)

script only has 2 lines;
#!/bin/bash
/etc/openhab2/broadlink_cli --type xxxxx --host 172.x.x.x --mac xxxxxxxxxxxx --send @LR-TV.power

Thanks

Use the version of executeCommandLine that makes use of Duration.ofSeconds.
Use the returned value and log it. The logging then will give information about what is the problem.

Well, you should update your openHAB :wink:

Don’t try sudo (openHAB will use the user openhab, which by default is not allowed at all for sudo, even if setting up to allow sudo, you would still get the password question, if omitting this you would create a really big security issue)

Please try

executeCommandLine("/bin/bash@@/etc/openhab2/LR-TVPower.sh")

Are the flags set to 755?
ls -l /etc/openhab2/LR-TVPower.sh should result ins something like this:

-rwxr-xr-x 1 openhab openhab   234 25. Jul 22:40 /etc/openhab2/LR-TVPower.sh

Tried it without sudo already. No luck.
Tried with the @@ no luck

Yes the permission flags are RWXRWXRX so 775 actually; more permissions, etc.

Use this syntax from the docs:

executeCommandLine(String commandLine, int timeout): Executes a command on the command and waits timeout milliseconds for the command to complete, returning the output from the command as a String

Then log the returned value.
Has openhab belong to a special group that allows access to the hardware ?

So something like this? executeCommandLine(“/etc/openhab2/LR-TVPower.sh”,10000)

That doesn’t return anything in the log. When I run it without that parameter it says it ran that command.

Not sure i need access to the hardware. It works from the CLI when I run the script; even if i run sudo -u openhab it works from the CLI…just not from openhab.

Thoughts?

Thanks!

see here:
https://community.openhab.org/t/how-to-use-executecommandline/149367/2?u=oliver2

As you are on OH 2.5.12 using DSL rule:

var result = executeCommandLine(“/etc/openhab2/LR-TVPower.sh”,10000)
logInfo( "rule foo bar", "{}", result )
logError( "rule foo bar", "{}", result )

That won’t “compile” in 2.5.11

2023-10-11 17:41:38.660 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model ‘Test.rules’ has errors, therefore ignoring it: [15,33]: no viable alternative at input ‘?’

[15,63]: no viable alternative at input ‘?’
[15,72]: mismatched input ‘)’ expecting ‘end’

var result = executeCommandLine(“/etc/openhab2/LR-TVPower.sh”,10000)

logInfo( “test”, “{}”, result )

logError( “test”, “{}”, result )

your code goes here

This may be due to the posting in the forum, but watch out for those double quotes. You want the utf-8 double quotes. Some of them in your post above are not the correct ones.

These are good: " "
These are not good: “ ”

Thanks; getting closer; now i see this:

I got it.
The script needed to point to the FULL path of that file; at the end; it only had the file name; which works from the cmd line; but not in openhab; had to put the full path in to call it from openhab.