Problems with Triggering a Shell Script over Rule

Hi,

I’m trying to trigger a simple shell script via Openhab 3 Rule.

only adb commands to start the shield are sent.

the script works fine when I start it manually with putty.

bash etc/openhab/scripts/power.sh

this is the script:

#!/bin/bash

adb kill-server

adb connect 192.168.0.165:5555

adb shell input keyevent 26

adb disconnect

when i trigger it over my rule, it dont work. the Shield doesnt start or shutdown.
but if I start it by hand over putty, as I said, it works

my rule


rule "Shield Control" 
when 
   Item shield_control received update ON
then
    executeCommandLine("/etc/openhab/scripts/power.sh")
    logInfo("Shield.rules", "Script gestartet")
end

any ideas?

See if it has anything to tell you

    var results = executeCommandLine("/etc/openhab/scripts/power.sh")
    logInfo("Shield.rules", "Script gestartet, " + results)
1 Like

here is the output

2021-02-22 15:57:10.301 [INFO ] [enhab.core.model.script.Shield.rules] - Script gestartet, null

Oh, I forgot you need a timeout, might get something then.

    var results = executeCommandLine(Duration.ofSeconds(60), "/etc/openhab/scripts/power.sh")
    logInfo("Shield.rules", "Script gestartet, " + results)
1 Like

okay now, i get a error.

* daemon started successfully

connected to 192.168.0.165:5555

error: device unauthorized.

This adb server's $ADB_VENDOR_KEYS is not set

Try 'adb kill-server' if that seems wrong.

Otherwise check for a confirmation dialog on your device.

disconnected everything

when i start the bash script in putty, the same error apears SOMETIMES.
but if I type in the lines of the script manually, it works.

adb connect 192.168.0.165
adb shell input keyevent 26

it seems to be related to the script, whenever I manually enter the 2 commands in putty, I have now tested it 10 times.

as far as I know / understand there are keys stored in the users folder /home//.android

ls /home/<user>/.android/
adbkey  adbkey.pub  debug.keystore

Running executeCommandLine runs with the openhab users privileges thus this users directory will be checked for the above keys which are not found.
Try to create a copy of this folder in oenhab users home directory ( /var/lib/openhab/ ) or try to run the command via ssh with a different user’s privileges.

1 Like

Hi,

Thanks for the answer.

I found out that the script or the commands are executed too quickly one after the other.

a simple “sleep 2” after the “adb connect” helped, now everything works fine.

Nevertheless, many thanks to everyone who helped.

The Android Debug Bridge could be an alternative for your script.

1 Like

that sounds good, but the binding is not available under OH3 right?

yes, it in the 3.1 snapshots

1 Like

Okay thx.i had openhab 3.0.1 installed.
Must i change to the snapshot Releases?

Edit

Is it possible to Upgrade over the openhab in config Tool?

Or which way?

This is ONE possibility.
I just saw that the binding is already in the OH 3.1.0 M1.
You can also wait, until 3.1 comes out. :slight_smile:
If your system is a production system, and it works well, you may not want to use well-tested modules.

You can use openhabian-config, menu 41 to change between release / testing / snapshot.
Other possibilities are described in the documentation.

1 Like

Okay works well. Thx