I have some issue on running a shell schript triggert by a rule in OH2.5. Unfortunately non of topcis discussed in this forum gave me the right hint to resolve my issue.
I created a very simple script, which works fine on manual execution.
However when I try to run it from OH it is not executed. Althought according to log the comand is executed the file 1local.txt is not creted.
Any hints for resolving that topic are very much apreciated.
- Hardware: RB 3+
- OS: Raspbian
- openHAB version: 2.5
Item Gat2Trigger_Run received command ON
logInfo(“gat2trigger”,“Rule to check Gate2 triggered”)
2020-02-10 13:05:22.126 [INFO ] [e.smarthome.model.script.gat2trigger] - Rule to check Gate2 triggered
2020-02-10 13:05:22.134 [INFO ] [lipse.smarthome.io.net.exec.ExecUtil] - executed commandLine ‘/home/openhabian/remote_test.sh’
-rwxr-xr-x 1 openhabian openhabian 46 Feb 10 13:18 remote_test.sh
Question is sudo really required to do whatever task you are trying to do?
If not try removing that. Chances are unless you configured this script to run without a password(using visudo) this is whats biting you.
Why don’t you log the executecommandline to see what it responds with in the log
See How to solve Exec binding problems. It’s an old post but still 100% relevant.
Script is being executed as user openhab but touch is to be done in the openhabian users directory.
This only will work if sudo can be executed as user openhab without any interactivity.
Change the script to do the touch in the /tmp directory to see if the file is being created there.
In case it is created you can also see the owners rights / the user that created the file.
I spent the whole weekend trying to get a simple script to run from OpenHAB. I already have several running that send commands to a library which controls the lights. It was an absolute bear to get to work. It would run fine in the terminal but not in a rule. Permissions needed to be fixed on the script, openhab user had to be in the group that owned the library and the last and most difficult one to run down was that the library created a pipe to communicate on the net and openhab user needed rights to that pipe. That one runs
This weekend was trying to get another script that plays a sound file using mpg123. Same thing, beating my brains out trying to figure out what is wrong.
To help things along, I found it useful to give openhab user terminal access so you can run the script in the terminal as user openhab
sudo -u openhab /bin/bash
thank you for your quick and helpful replies. Your hints were very helpful to resolve the problem. The issues was the user openhab that was not authorized to create a file in that directory (owned by openhabian)