Noob scripting question with android ADB commands


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Noob scripting question with android ADB commands
# 1  
Old 10-21-2011
Noob scripting question with android ADB commands

Hi I'm pretty new to scripting and I've been googling around looking for an answer but have yet to come up with a proper solution. I work with multiple android devices at a time and I'm looking to simplify my life with a script. Basically I'm looking for a script that takes the device ID's and then issues another command with those unique ID's.

Example:
$ adb devices
Outputs:

List of devices attached
a0000012b044c2 device
39353A76314800EC device
464119A50E1E338E device
a00000128c6400 device

So I now need to the script to plug in those 4 ID's into a command like:

$ adb -s a0000012b044c2 push myfile.zip /sdcard/ |
adb -s 39353A76314800EC push myfile.zip /sdcard/ |
adb -s 464119A50E1E338E push myfile.zip /sdcard/ |
adb -s a00000128c6400 push myfile.zip /sdcard/


To be a bit more clear I use the sed command to output the ID's into a file by themselves, I just don't know how to recall those ID's as variables into a command.

So my output file reads:

a0000012b044c2
39353A76314800EC
464119A50E1E338E
a00000128c6400

Now I need to input those ID's into my shell:

$ adb -s 1stIDfromFile push myfile.zip /sdcard/ |
adb -s 2ndIDfromFile push myfile.zip /sdcard/ |
adb -s 3rdIDfromFile push myfile.zip /sdcard/ |
adb -s 4thIDfromFile push myfile.zip /sdcard/

Any help or if someone can point me in the right direction would be appreciated.

Thanks

---------- Post updated at 11:41 PM ---------- Previous update was at 10:16 PM ----------

Well maybe I posted a bit premature, I did some more searching and found the solution to my question. If anyone is interested here is the script I used

#!/bin/sh
adb devices > devices.txt

sed -e s/devices//g -e s/of//g -e s/List//g -e s/attached//g -e s/device//g devices.txt > test3.txt

rm devices.txt

while read line
do
set -- `echo $line | awk -vFS=',' '{print $1,$2,$3,$4,$5,$6,$7,$8,$9,$10}'`
adb -s $1 reboot recovery | adb -s $2 reboot recovery | adb -s $3 reboot recovery | adb -s $4 reboot recovery | adb -s $5 reboot recovery | adb -s $6 reboot recovery | adb -s $7 reboot recovery | adb -s $8 reboot recovery | adb -s $9 reboot recovery | adb -s $10 reboot recovery
done < test3.txt

exit 0

I know it's a bit messy but it works, one concern that I have is on the last adb command

adb -s $10 reboot recovery

it only picks up $1 and not $10, any idea on that?

Thanks

Last edited by Onyoursix; 10-21-2011 at 12:10 AM..
# 2  
Old 10-21-2011
try with "$10"

---------- Post updated at 09:24 AM ---------- Previous update was at 09:18 AM ----------

Try this command

Code:
 
adb devices | nawk 'NR>1{printf("adb -s %s push myfile.zip /a/ |\n",$1)}'

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 10-21-2011
Oh man that command is money! Thank you!!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Total Noob BASH scripting question

Hello All, I have a file of ip addresses called activeips.txt What I'm trying to do is run a simple bash script that has a loop in it. The loop is a cat of the IP addresses in the file. The goal is to run 2 nmap commands to give me outputs where each address in the list has an OS... (11 Replies)
Discussion started by: Dirk_Pitt
11 Replies

2. Shell Programming and Scripting

Noob to scripting needs some assistance

Hello, I am in a Unix class and have been out of town. I have been tasked to generate a couple of scripts and ahve never done it before. I have a virtual machine running Ubuntu. The task is below Prompt the system administrator for all valid input parameters Generate a menu to ask which... (1 Reply)
Discussion started by: jkeeton81
1 Replies

3. Android

Basic commands for android!!

Hi, I have a n android phone and just rooted it. I access it using 'terminal Emulator'. I performed many basic linux-like commands in the terminal like rm,ls,df,reboot etc and they are working fine. But many of them are not like man <something>, clear,du etc. Can any of you please help to... (20 Replies)
Discussion started by: shekhar_4_u
20 Replies

4. Shell Programming and Scripting

Shellscript to copy music from handy to pc over Android Development Bridge (ADB)

Hi Friends, I want to copy my .mp4 files from a file of my mobile to my pc using the programm adb (Android Development Bridge). My Script: ./copyfiletopc /sdcard/Playtube ~/musik/PlayTube \.mp4 #!/bin/bash # $1 = from dir # $2 = to dir # $3 = search # adb is the... (2 Replies)
Discussion started by: Bergiu
2 Replies

5. Shell Programming and Scripting

Noob Expect Scripting Question

I'm having some difficulty with convincing Expect to do what I need.. I have a loop that waits for input, a specific phrase of text followed by a single word. I need Expect to capture that word following the specific phrase. It should then store the word in a variable. I'm fairly sure it's... (6 Replies)
Discussion started by: LongLeafTea
6 Replies

6. Shell Programming and Scripting

Noob to Shell Scripting

Hello. I'm attempting to create a shell script to assist me by saving time with one of my hobbies. I am an Android Enthusiast and currently build a few roms for one of the devices. One of the roms I make is ported from a different device to mine (I get the original for the HTC Desire HD and... (3 Replies)
Discussion started by: JHutson456
3 Replies

7. UNIX for Dummies Questions & Answers

NOOB - Scripting to make an App work

Hello everyone. i work in a school and i ran into an application today that is a real pickle. i know how to make it work, but i would need to script it. The way to make it work would be to have a script check each local user profile on login, see if the directory already exists, do nothing... (27 Replies)
Discussion started by: jscan
27 Replies

8. Android

Android Scripting Environment: Shell Scripting and Android

I just upgraded to Android 2.2 from 2.1. The GPS issue that was troublesome in 2.1 seems to have been fixed. Some of web browsing seems faster, but it could just be my connection is better today ;) Flash works in some browsers but not very good and it is too slow for Flash apps designed for... (0 Replies)
Discussion started by: Neo
0 Replies

9. Android

Example Linux Commands on Android

In case you are interested, here is a partial list of linux-like commands on Android OS: /sbin adbd devmgr recovery dfta init dfta.sh fat.format redbend_ua /system/bin (partial list) sh date netstat mount umount (0 Replies)
Discussion started by: Neo
0 Replies

10. UNIX for Dummies Questions & Answers

Noob learning Unix: backup commands

I am trying to learn some unix here and i have some question that i would like to ask: What's the most basic backup command? What is the command to pause a backup? What is the command to resume backup? Can we backup a job that is running ? How can we pause the backup of the job and than... (1 Reply)
Discussion started by: lotusx
1 Replies
Login or Register to Ask a Question