Hi!
I need to run a bash script from a rule like this:
rule "Cron job every minute"
when
Time cron "0 0/1 * * * ?" // every 1 minutes
then
createTimer(now, [ |
var results = executeCommandLine("/etc/openhab2/scripts/checkBTicino.sh", 5000)
// code to process results
logInfo("cronBTicino", "results : ", results)
])
end
That is strange. In an other case moving the command into echo helped.
So I checked to see if it works from the command line and it does but there is one difference that I was not aware of before. Using this combination of comands it looks like the length of the output in a line is shortened to a specific amount of characters. It could be that the string you are looking for is cut off.
e.g. output in the console
230 β Active β 80 β 2.5.12 β openHAB Add-ons :: Bundles :: Amazon Echo Control Binding
output via command line
230 β Active β 80 β 2.5.12 β openHAB Add-ons :: Bundles :: A
The openhab service normally runs as user openhab.
You can check that by having a look to which is the user the java process runs under ( ps -ef ).
Thus the user openhab:openhab needs to have read ( r ) and execute ( x ) permissions on the executable. You can check that by using
ls -ld /etc /etc/openhab2 /etc/openhab2/scripts /etc/openhab2/scripts/checkBTcino.sh
to check if settings for all directories and the script at once.
In case a directory is not owned by user openhab nor group openhab world needs to have (r)x permissions.
Running your script with sudo permssion is a hint to that the ownership is done in a way that the owner/group does not have read/execute permission.
Redirect the output of your script to a temporary file ( before greping ).
You may do this to check how the output looks like executing it from a rule. Just to check if there is any output at all or if the lines are shorter than expected and thus there is no match.
( it could be that there are two problems ( permission and length of the output lines ) )