Bash script not working as I would expect

Here’s my .bash_profile

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
export GOBIN="$HOME/projects/bin"
export GOPATH="$HOME/projects/src"

What does ps aux | grep openhab show?

This is what I get from ps aux | grep openhab

root      1178  0.0  0.0 113448  1812 ?        Ss   Jan12   0:00 /bin/sh /opt/openhab/runtime/bin/karaf server
root      1424  4.5 50.0 5702076 2024568 ?     Sl   Jan12 526:57 /usr/bin/java -Dopenhab.home=/opt/openhab -Dopenhab.conf=/opt/openhab/conf -Dopenhab.runtime=/opt/openhab/runtime -Dopenhab.userdata=/opt/openhab/userdata -Dopenhab.logdir=/opt/openhab/userdata/logs -Dfelix.cm.dir=/opt/openhab/userdata/config -Djava.library.path=/opt/openhab/userdata/tmp/lib -Djetty.host=0.0.0.0 -Djetty.http.compliance=RFC2616 -Dorg.ops4j.pax.web.listening.addresses=0.0.0.0 -Dorg.osgi.service.http.port=8080 -Dorg.osgi.service.http.port.secure=8443 -Djava.awt.headless=true -XX:+UseG1GC -Djava.endorsed.dirs=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/jre/lib/endorsed:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/lib/endorsed:/opt/openhab/runtime/lib/endorsed -Djava.ext.dirs=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/jre/lib/ext:/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/lib/ext:/opt/openhab/runtime/lib/ext -Dkaraf.instances=/opt/openhab/userdata/tmp/instances -Dkaraf.home=/opt/openhab/runtime -Dkaraf.base=/opt/openhab/userdata -Dkaraf.data=/opt/openhab/userdata -Dkaraf.etc=/opt/openhab/userdata/etc -Dkaraf.log=/opt/openhab/userdata/logs -Dkaraf.restart.jvm.supported=true -Djava.io.tmpdir=/opt/openhab/userdata/tmp -Djava.util.logging.config.file=/opt/openhab/userdata/etc/java.util.logging.properties -Dkaraf.startLocalConsole=false -Dkaraf.startRemoteShell=true -classpath /opt/openhab/runtime/lib/boot/org.apache.karaf.diagnostic.boot-4.2.7.jar:/opt/openhab/runtime/lib/boot/org.apache.karaf.jaas.boot-4.2.7.jar:/opt/openhab/runtime/lib/boot/org.apache.karaf.main-4.2.7.jar:/opt/openhab/runtime/lib/boot/org.apache.karaf.specs.activator-4.2.7.jar:/opt/openhab/runtime/lib/boot/osgi.core-6.0.0.jar org.apache.karaf.main.Main
root     21664  0.0  0.0 112716   968 pts/0    S+   20:17   0:00 grep --color=auto openhab

Just to be sure: is that the .bash_profile from the root user?

Yes, that’s correct.

When the script actually runs from OH it seems to be missing the GOPATH="$HOME/projects/src". Might be because it runs as a command directly from OH without the full shell context.
I suggest to run a simple test script to show the environment variables when triggered from OH as well as some other basic info like user context.

1 Like

You could try fully qualifying the command in the script.

1 Like

Why? Do you realize that running openhab as root is not a good idea? It also has no advantages!

1 Like

Tried that also, still no luck. I’m looking an alternative way, by using the Rest API.

If there are any further ideas around what I can do to resolve this issues, then please add your comments.