Executing a Local Script in a Remote ADB Shell
It can be useful to write and store scripts on a local development machine and run them remotely on one or more Android devices. This post covers how this is done.
Software Versions
Instructions
Create a sample script to execute. The shebang line is written for Android.
script.sh
Executing commands over ssh is relatively easy, however most Android devices do not have sshd enabled.
A script can not be piped into adb. The following strategy can be used instead. This will probably only work for sh scripts. The shebang is ignored.
If the shebang is important, a script like the following can be used to execute other scripts remotely.
adb-remote-script.sh
The remote execution script can be used as followed.
The above is a proof of concept. Interpreters like perl and python are probably not installed. If piping input into the shebang does not work, another case can be written. For example, the following could be used if elixir were available. This case needs to be placed above the other case statements.