Hello,
am in the middle of migration to OH3. After searching 4 days in the forum, I got a lot closer - but do not get this to work. To pull data from my remote SQL data base I have a script that provides items and things from my SBFspot database. Later I also want to use scripts to write specific data into mySQL.
Environment:
- Ubuntu server 21.04
- Openhab 3.1.0 as docker (standard configuration)
- On my server (not as docker): mySQL Server 8.0.25
I was able to call the script as root within Linux with result from my remote DB. So mySQL on the new machine also works.
I can call the script from a rule (conform to latest documentation):
var String test = executeCommandLine(Duration.ofSeconds(10),"/openhab/conf/scripts/sma.script", "ETotal")
For testing my bash script (chown, whitelist, chgrp) I have included a simple textfile creation into the rule - to be shure it is executed :
#!/bin/bash
user=openhab
password=mypassword
host=192.168.178.199
sql_name=$1
echo "Sql Name " $sql_name >> /openhab/conf/scripts/temp_output.txt
SMA_Val=$(mysql --defaults-extra-file=/openhab/conf/scripts/config.cnf -N -e "select $sql_name from SBFspot.Inverters")
case "$sql_name" in
EToday) val=`echo "scale=2 ; $SMA_Val / 1000" | bc`;;
ETotal) val=`echo "scale=2 ; $SMA_Val / 1000" | bc`;;
*) val=$SMA_Val;;
esac
echo $val
And the text file gets created and filled
SQL Name ETotal
As openhab executes inside the docker, my (fist) biggest issue was to find out - that the docker has different paths:
Host volume Path in container
/opt/openhab/conf /openhab/conf
This is resolved. BUT in the log files show the following and I get no result from the sql statement:
2021-07-24 22:37:24.251 [INFO ] [.openhab.core.model.script.Test Exec] - /openhab/conf/scripts/sma.script: line XX: mysql: command not found
/openhab/conf/scripts/sma.script: line XY: bc: command not found
I guess the docker on sh command line cannot execute / interpret the mysql and bc!
My docker PATHs /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Is my assumption right, the sql engine is not found by the openhab docker?
Any suggestion how to fix this?
Or do I need to do a fresh install of OH3 without docker?
Thanks for any hint or advise.
Bernd