运行ADB命令的Bash脚本不会遍历设备列表 [英] Bash script running ADB commands won't iterate through list of devices

查看:257
本文介绍了运行ADB命令的Bash脚本不会遍历设备列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的bash脚本,它遍历设备列表并向Android设备运行adb shell命令。代码如下:

I have a simple bash script that iterates through a list of devices and runs adb shell commands to Android devices. The code is below:

echo "Displaying devices to be configured:"
adb devices | sed "1d ; $ d"
echo ""
echo "###########################"
echo "#                         #"
echo "# Starting configuration! #"
echo "#                         #" 
echo "###########################"
echo ""

while read -r udid device usb product model device2; do

echo ""
echo $usb
echo ""

# INSTALL THE APPS
adb -s "$usb" install ./src/apps/1.apk
adb -s "$usb" install ./src/apps/quicksupport.apk

# SET WIFI OFF
adb -s "$usb" shell settings put global wifi_on 0

# SET SOUND TO 0
adb -s "$usb" shell service call audio 7 i32 3 i32 0 i32 1

# SET AUTO TIME ZONE OFF
adb -s "$usb" shell settings put global auto_time_zone 0

# SET INSTALL NON MARKET APPS ON
adb -s "$usb" shell settings put global install_non_market_apps 1

# REBOOT
adb -s "$usb" reboot

done < <(adb devices -l | sed "1d; $ d")

echo ""
echo "###########################"
echo "#                         #"
echo "# Configuration complete! #"
echo "#                         #" 
echo "###########################"
echo ""

运行时,代码将在一个设备上成功运行所有配置。当插入两个设备时,输出如下:

When ran, the code will successfully run all configurations on one device. When plugged into two devices, the output reads as follows:

Displaying devices to be configured:
0123456789ABCDEF    device
0123456789ABCDEF    device

###########################
#                         #
# Starting configuration! #
#                         #
###########################


usb:336592896X

[100%] /data/local/tmp/1.apk
    pkg: /data/local/tmp/1.apk
Failure [INSTALL_FAILED_ALREADY_EXISTS]
[100%] /data/local/tmp/quicksupport.apk
    pkg: /data/local/tmp/quicksupport.apk
Failure [INSTALL_FAILED_ALREADY_EXISTS]
0123456789ABCDEF       device usb:337641472X product:msm8960 model:msm8960 device:msm8960
Result: Parcel(00000000    '....')

###########################
#                         #
# Configuration complete! #
#                         #
###########################

似乎返回 adb devices -l <​​/ code>命令的其余部分,然后退出循环。这是bash的问题吗?这是adb的问题吗?我已经尝试了好几天了。

It seems to return the remainder of the adb devices -l command and than break out of the loop. Is this an issue with bash? Is this an issue with adb? I've been trying to figure this out for days.

注意:结果:包裹(00000000'....')在声音设置为零后立即发生输出。

Note: The Result: Parcel(00000000 '....') output occurs directly after the sound is set to zero.

注意:不要介意失败[INSTALL_FAILED_ALREADY_EXISTS] ,这是因为已经安装了应用程序。

Note: Don't mind the Failure [INSTALL_FAILED_ALREADY_EXISTS], that occurs because the apps are already installed. That's not what I'm concerned about.

注意:发布 adb设备-l | hexdump -C

00000000  4c 69 73 74 20 6f 66 20  64 65 76 69 63 65 73 20  |List of devices |
00000010  61 74 74 61 63 68 65 64  0a 30 31 32 33 34 35 36  |attached.0123456|
00000020  37 38 39 41 42 43 44 45  46 20 20 20 20 20 20 20  |789ABCDEF       |
00000030  64 65 76 69 63 65 20 75  73 62 3a 34 33 37 33 38  |device usb:43738|
00000040  37 32 36 34 58 20 70 72  6f 64 75 63 74 3a 6d 73  |7264X product:ms|
00000050  6d 38 39 36 30 20 6d 6f  64 65 6c 3a 6d 73 6d 38  |m8960 model:msm8|
00000060  39 36 30 20 64 65 76 69  63 65 3a 6d 73 6d 38 39  |960 device:msm89|
00000070  36 30 0a 30 31 32 33 34  35 36 37 38 39 41 42 43  |60.0123456789ABC|
00000080  44 45 46 20 20 20 20 20  20 20 64 65 76 69 63 65  |DEF       device|
00000090  20 75 73 62 3a 33 33 36  35 39 32 38 39 36 58 20  | usb:336592896X |
000000a0  70 72 6f 64 75 63 74 3a  6d 73 6d 38 39 36 30 20  |product:msm8960 |
000000b0  6d 6f 64 65 6c 3a 6d 73  6d 38 39 36 30 20 64 65  |model:msm8960 de|
000000c0  76 69 63 65 3a 6d 73 6d  38 39 36 30 0a 0a        |vice:msm8960..|
000000ce


推荐答案



This is slightly more efficient and less error prone way of doing the same thing:

DeviceConfig () {

# INSTALL THE APPS
adb -s $1 install ./src/apps/1.apk
adb -s $1 install ./src/apps/quicksupport.apk

# SET WIFI OFF
adb -s $1 shell settings put global wifi_on 0

...

adb -s $1 reboot

}

for usb in $(adb devices -l | awk '/ device usb:/{print $3}'); do DeviceConfig $usb; done

这篇关于运行ADB命令的Bash脚本不会遍历设备列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆