Hi,
in OH 2.5 the following ExecuteCommandLine was working:
executeCommandLine(“sudo /app/scripts/openhab/myscript.sh”, 60000)
I change to:
executeCommandLine(Duration.ofSeconds(60), “sudo /app/scripts/openhab/myscript.sh”)
In OH3 I always get the error:
Failed to execute command Line
Of course the user openhab has the “sudoers” right to execute the command…
Scripts without “sudo” in Front are working.
you have to either replace your space-characters with @, or seperate all of your arguments.
e.g.
executeCommandLine(Duration.ofSeconds(60), “/usr/bin/sudo”, “/app/scripts/openhab/myscript.sh”)
You’re welcome.
I’m rather new to openhab myself, so I’m not quite sure about the @-variant. It’s possible you’d have to double it up (@@), but I skipped that alltogether, because I didn’t like the look of it.
Glad it works for you now.
I need to start a script with executeCommandLine. The script needs 2 Parameter with spaces.
How can I start the script out of a rule?
Here’s the working example of OH 2.5:
executeCommandLine("sudo /app/scripts/openhab/mailsenden.sh abc.def@provider.com “ALARM: Rauchmelder ausgelöst” “Rauchmelder im Wohnzimmer hat ausgeloest” ", 60000)
How can I archive this in OH3?
I had tried:
executeCommandLine(Duration.ofSeconds(60), “/usr/bin/sudo”, "/app/scripts/openhab/mailsenden.sh abc.def@provider.com “ALARM: Rauchmelder ausgelöst” “Rauchmelder im Wohnzimmer hat ausgeloest” "
executeCommandLine(Duration.ofSeconds(60), “/usr/bin/sudo”, "/app/scripts/openhab/mailsenden.sh", "abc.def@provider.com","ALARM: Rauchmelder ausgelöst", "Rauchmelder im Wohnzimmer hat ausgeloest")
b) I do not know if quoting for space separated parameters work. So just in case it still does not work concatenate the single words with e.g. minus ( - ) to make them one long string. I case this is not the problem you can remove the minus symbol later again.
c) to use sudo openhab needs to be member of the sudo group which is not the default.
Question: do you really need sudo prvileges for myscript.sh ? For security reasons you should only use sudo where it is required as script will be executed as user root. If sudo is required of course depends on the content of myscript.sh which is not shown
I’m not an expert, but I think the issue is that you are passing it as one string. Where there is whitespace separators in the string, all of the components either side of the whitespace have to be passed as separate parameters for it to work.
You are building and passing a single long string containing the whitespace separators, which I don’t think will work.
Based on the example you gave, there is no space in that part of the string, so I don’t think it needs breaking into separate parameters. If I’m correct, you only need to break where there are spaces (whitespace) in the command line.
Did you try it also without the timeout part?
The timeout should be used when you need the response from your execution.
Therefore the reponse has to be written into a variable.
Maybe thats already the reason for failing here.
If you just want to execute a script and it doesn’t matter what the reponse is, you should omit the duration parameter.