0

I use a bash script to automate processes on Android devices in my office. I call the shell like this in the script: (Let the ... stand for any amount of adb shell commands.)

#!/bin/bash

...

adb shell do stuff
adb shell do stuff
adb shell do stuff

...

exit

These scripts function very well. I have already done research on sending multiple commands to a single instance of shell; I'm wondering if they are as efficient as they can be though. Am I using a lot of system resources? Could this potentially raise issues in the future when I'll be running very very large automation scripts using this process?

jagdpanzer
  • 693
  • 2
  • 10
  • 35

2 Answers2

1

Starting of the new sh process does not take a lot of time or resources. Queuing multiple commands to the same sh instance does not provide any noticeable performance improvement. Just be mindful of what commands you run in those shell sessions. Some commands like input are not native binaries but java applications which take longer time to start - so do not expect to be able to fire multiples of those per second.

Alex P.
  • 30,437
  • 17
  • 118
  • 169
  • This actually explains a lot. This question is related to a scenario in my other question, http://stackoverflow.com/questions/39278510/adb-shell-input-command-changes-when-ran-on-multiple-devices/39282793 Slowing down my `input` commands allowed those commands to fire through accurately. Pretty interesting that the `input` commands are java apps. – jagdpanzer Sep 02 '16 at 13:42
1

Not a big deal, but you can do

adb shell <<!
    do stuff
    do stuff
    do stuff
!

which is sometimes useful if you have some ifs or loops as it's much easier to write and visualize.

Diego Torres Milano
  • 65,697
  • 9
  • 111
  • 134
  • *which is sometimes useful* but still **does not provide any noticeable performance improvement** – Alex P. Oct 17 '16 at 16:46
  • Perhaps it does: `time for n in {0..9999}; do adb shell ls -l ">" /dev/null; done real 3m29.764s user 0m1.032s sys 0m1.560s $ time while [ $i -lt 10000 ] > do > ls -l > /dev/null > i=$(( i + 1 )) > done 2m1.52s real 0m2.43s user 0m5.68s system` – Diego Torres Milano Oct 20 '16 at 21:18