Page 1 of 1
AndroidTV ADB - bash script does not work
Posted: Tuesday 20 April 2021 23:25
by Wolly76
Dear all,
I'm trying to implement a connectivity to my AndroidTV using ADB.
When executing the proper calls in the command line it all works:
Code: Select all
adb kill-server
adb start-server
adb connect 192.168.2.7
adb shell input keyevent KEYCODE_POWER
However, if I add these lines to a shell script (according to this
thread), it doesn't work properly and I got the following error message after the last line:
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.
Apparently the ADB-server isn't started. I don't get why this way is not working as it works when executing the lines manually.
Does anybody has a clue?
thanks!
Re: AndroidTV ADB - bash script does not work
Posted: Wednesday 21 April 2021 11:15
by erem
when you run the commands manually, what user is this?
when you run the shell script, what user runs it? same?
post your script and it's properties.
Re: AndroidTV ADB - bash script does not work
Posted: Wednesday 21 April 2021 15:38
by Wolly76
Thanks Rob for consideration. Effectively my shell script isn't more then the manual handled lines.
But your comment about the user is pointing me probably to the right direction.
The "manual lines" were executed as user pi, however, the shell script was executed as root (sudo) as the owner/modes were not set to user pi.
I have changed those and it appeared to work although I'll have to test a bit more thoroughly. I wasn't aware of the fact that the finger print for ADB on the Android TV was user dependent.
Re: AndroidTV ADB - bash script does not work
Posted: Thursday 22 April 2021 11:16
by Wolly76
Alas, it's not solved yet

.
so this is the shell script
Code: Select all
#!/bin/sh
echo "::: Start ADB connect script :::"
adb kill-server
adb start-server
adb connect 192.168.2.7
adb shell input keyevent KEYCODE_POWER
echo "::: End ADB connect script :::"
With owner/mode as:
4 -rw-rw-rw- 1 pi pi 261 Apr 22 10:58 testAdbStartScript.sh
which I run by :
bash testAdbStartScript.sh
Thanks in advance.
Re: AndroidTV ADB - bash script does not work
Posted: Thursday 22 April 2021 11:26
by Wolly76
Just playing around a bit, with some trial and error I found out the cause.
In my script I started with "adb kill-server" then continued with start-server etc...
By applying once at the start, then skipping this call resulted in a working script.
so the proper script should become:
Code: Select all
#!/bin/sh
echo "::: Start ADB connect script :::"
adb start-server
adb connect 192.168.2.7
adb shell input keyevent KEYCODE_POWER
echo "::: End ADB connect script :::"
Then I still had issues when calling this script in Domoticz but that had another cause.
I used osExecute('bash ~/testAdbStartScript.sh') but when I changed the "~" to /home/pi/ then it worked:
Code: Select all
osExecute('bash /home/pi/testAdbStartScript.sh')
The learning curve is slow ....
Code: Select all
local function osExecute(cmd)
local fileHandle = assert(io.popen(cmd, 'r'))
local commandOutput = assert(fileHandle:read('*a'))
local returnTable = {fileHandle:close()}
return commandOutput,returnTable[3]
end
Re: AndroidTV ADB - bash script does not work
Posted: Thursday 22 April 2021 12:22
by erem
if you change
to
you can run the script like this
Code: Select all
osExecute('/home/pi/testAdbStartScript.sh')
you are running bash to start sh to execute the script.
you do not need sh.