executeCommandLine doesn't work

I’m getting crazy… I have openhab 2 installed with distro. Everything works well but I can’t run any script.
I think it is a problem of permission. Openhab is installed on raspberry pi and automatically started at boot as service.
If I execute the script from account pi it works, if I do that using the openhab UI the command is received but nothing happens…
The owner and the group of the script file is openhab.
I don’t know what to do anymore… If someone can help me I will be very grateful
Thank you all

Add a timeout to executeCommandLine so you get the results. There will usually be an error in there.

val results = executeCommandLine("command", 5000) // wait up to five seconds
logInfo("Test", results)

Thanks for your reply but I think the problem is not there.
If I launch openhab from my pi shell using ./start.sh, my script runs correctly but if I start openhab at boot, it doesn’t work. I think it could be a problem of permissions but are days that I think about without any progress :frowning:

But if you log out the results as I demonstrate above it will actually tell you the error that occurs which should tell you what is wrong and give you a clue how to fix it. It will even tell you if there is a permissions problem.

I did as you wrote me. In the openhab.log I see: [info] executedcommandLine ‘/etc/openhab2/scripts/prova.sh’ but the script haven’t done nothing actually. It doesn’t work and I don’t see any other clue in the openhab.log

Do you use the full path to all of the commands in prova.sh? When you run a program as a service it does not have any of the shell environment configuration you are use to. So, for example, if you are running echo, you may need to specify /bin/echo instead.

I did that :frowning:
I have the script etc/openhab2/scripts/prova.sh that is:

#!/bin/sh
sudo -u pi /usr/bin/kodi-standalone

and a rules that is:

rule "Kodi start"
when
Item KodiTV received command ON
then
executeCommandLine=(“etc/openhab2/scripts/prova.sh”,5000)
end

Ah, but you don’t have the full path to sudo

/usr/bin/sudo

Furthermore, when run as a service with a manual install, OH is running as root. There is no need to sudo if you are already root and the sudo will likely fail because root is not a sudoer account.

And the reason why you are not seeing anything in the log is because you did NOT do what I said. You need to actually log out the result to see it in the logs. Had you logged the results you would probably have seen an error saying the root is not a member of sudoers.

rule "Kodi start"
when 
    Item KodiTV received command ON
then
    val results = executeCommandLine=("etc/openhab2/scripts/prova.sh",5000)
    logInfo("Test", results)
end

I wrote the rule exactly as you said but I don’t know where to see the logInfo. I only see /var/log/openhab2/openhab.log
Excuse me but I am newby of Linux and openhab. Many thanks for your help

With a manual install I’m not sure where the log files go. That is a reasonable place for it to be. Another location could be whereever you installed it/userdata/logs/openhab.log.

As a newbe to Linux I would once again encourage you to install via apt-get. I’m not sure this would be a problem if it were installed that way, and if it were I’d have more to go on to help you because I can make assumptions about where things are, what permissions are set and what user OH is running under.

But I installed openhab 2 with apt-get. I didn’t use manual install

I apologize. I got this thread confused with another one.

OK…

When OH is installed via apt-get, openHAB is running as a limited user openhab. In your script you are running sudo which means you need to add the openhab user to sudoers.

You can do this by running

sudo visudo

Copy the line that starts with “pi” and replace the “pi” with “openhab”.

That should fix the problem, if sudo is the only problem.

sorry I don’t understand… I have to write sudo visudo in my script file?

No, you need to configure the sudo utility to allow the openhab user to execute commands as root. To do this you edit the sudoers file. However, if you mess that file you you can render your machine unusable so there is a special command called visudo you use to edit /etc/sudoers. This command will test your changes to make sure they are valid before activating the changes. If you just edit the file directly and mess something up, NO user on the system will be allowed to execute sudo.

You’re right! Actually the problem was due to sudoers and to the fact that I didn’t know that I had to write the complete path of the command when using the openhab user.
Thanks a lot for your help, after many and many wrong attempts, you put me on the right way.
Thanks again :slight_smile:

I am trying to use ExecuteCommandLine in rule but getting an error in the log saying
2017-04-02 23:38:45.950 [ERROR] [internal.handler.ScriptActionHandler] - Script execution failed: ReferenceError: "executeCommandLine" is not defined in <eval> at line number 1

I’m using openhabian and this was installed from SD drive. I have also installed the Exec Binding using the PaperUI.

Is it possible the Exec Binding was not installed properly?

My rule was inserted into PaperUI and the action module of the script is as follows

executeCommandLine(" ./etc/openhab2/scripts/startATVPN.sh")

Which version of the Exec binding did you install? I thought that executeCommandLine was a default action but if it does need to the Exec binding installed to use it, you might need the 1.x version, not the 2.x version. I’m just guessing through. It has been a long time since I’ve used either.

Indeed it is Exec Binding 2.0.0 that I have installed using PaperUI. How could I get a hold of v1.x?
It was suggested that Exec Binding was needed by Ken_Van_Camp in the post below. I’m not using a sudo command so ignore the latter part of his post.
I feel I am really close to getting this to work, and think it is just a syntax thing. Tried with dot before script path and without, with ~ before and without, with Speech Marks and without. Also tried using CallScript function instead but no joy.
It might be easier for you to assist me troubleshoot if I could paste the whole .rule file code. Do you have any idea where the PaperUI would save this?
(the folder /etc/openhab2/rules is empty)

You can enable “Show Legacy Bindings” or something like that in the PaperUI system configs. This will show both the 1.x and 2.x versions of the bindings.

There is nothing you can change in the .rules file to make this work

Wait, you are using the Next Gen Rules engine? I don’t know if that supports any actions at all. In any case, all bets are off with the Next Gen engine.To quote from the docs:

this is available within openHAB 2 only as an experimental feature.

Note: If you use it, this is at your own risk. Especially, you should not expect any documentation besides what is available on the Eclipse SmartHome website.

Everything written above, and almost everything you see on this forum and within the openHAB docs are specific to the current Rules DSL which requires you to write rules by hand in .rules files. PaperUI is not involved at all.