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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shellscript to copy music from handy to pc over Android Development Bridge (ADB)
# 1  
Old 07-29-2013
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
Code:
#!/bin/bash
# $1 = from dir
# $2 = to dir
# $3 = search
  
# adb is the AndroidDevelopmentBridge
# adb shell [command] executes the command
# on the smartphone.

adb shell ls $1 | grep -i $3 > filenames.txt
  
    for i in `cat filenames.txt`
    do
  # adb pull [source] (target) copies the requested files
  # from smartphone to pc
  
  # Parameter:
   # $1/$i = /sdcard/PathSmartphone/CurrentFilename.mp4
   # $2/$i = ~/PcPath/CurrentFilename.mp4
  adb pull "$1/$i $2/$i"
done

First the script starts with
Code:
 adb shell ls $1 | grep -i $3 > filenames.txt 

which saves all .mp4 files to the file filenames.txt.

The file looks like this:
0nrmWz3RVQA.mp4
5AyJyoiH5-k.mp4
...

After that the script should read every line in the file after each other and copy all files whith this comand
adb pull "$1/$i $2/$i"

but however after the variable $i the rest ($2/$i) is automatically placed in front of the parameters, so that "$1/$i $2/$i" doesn't display the two parameters:
[source] (target)
/sdcard/PlayTube/0nrmWz3RVQA.mp4 root/musik/PlayTube/0nrmWz3RVQA.mp4

but:
/root/musik/PlayTube/0nrmWz3RVQA.mp4
/root/musik/PlayTube/5AyJyoiH5-k.mp4

and the result of testing
Code:
 echo "$1/$i bla"

in the for loop is:
blaard/PlayTube/0nrmWz3RVQA.mp4
blaard/PlayTube/5AyJyoiH5-k.mp4
and not:
sdcard/PlayTube/0nrmWz3RVQA.mp4 bla
sdcard/PlayTube/5AyJyoiH5-k.mp4 bla

And I don't know why?Smilie

Sorry for my bad English Smilie
Thanks in advance
# 2  
Old 07-30-2013
Did you try writing to a file and check instead of echoing
Code:
 echo "$1/$i bla"

?

Does your filenames.txt look clean without any <CR> at the end of the line ?
This User Gave Thanks to rajamadhavan For This Post:
# 3  
Old 08-04-2013
1. Try to write what to a file?
2. <CR> ??
Smilie

---------- Post updated 08-04-13 at 05:16 AM ---------- Previous update was 08-03-13 at 04:37 PM ----------

Ahhh Smilie
Now I know what <CR> means, and if I remove the <CR> with an texteditor manually, it works.
But is it possible, that the command ls does this automatically?
Or do you know an alternative maybe?

Thanks in advance
Marco
Login or Register to Ask a Question

Previous Thread | Next Thread

6 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Remote copy through shellscript

I am using RedHat 4.4 Version Operating System. I want to copy one file from source to destination.I don't want to give a password when I am executing the below shell script. code: #!/bin/bash scp -r file.zip 192.168.1.5:/root/ Here it asking a password to enter,Is there any way give a... (2 Replies)
Discussion started by: kannansoft1985
2 Replies

2. UNIX for Dummies Questions & Answers

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... (2 Replies)
Discussion started by: Onyoursix
2 Replies

3. 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

4. Shell Programming and Scripting

Building a DOS .bat file that will root my Droid 2 phone using adb

1. What I am doing? Building a DOS .bat file that will root my Droid 2 phone using adb commands in the .bat file. (Just for the fun of it and to help me learn "stuff".) 2. Problem: Here are the problem steps to accomplish this task manually in an adb shell: adb shell (Prompt is $) cd... (2 Replies)
Discussion started by: chrstdvd
2 Replies

5. Shell Programming and Scripting

Probably easy question for handy person!!!

I have given file with three columns,example: mm234 5 22 mn237 6 45 de987 4 41 I have to check for input values in second and third column and if it is not numeric I have to deleted using grep function. I keep trying. But help from pros might help me. We know that there is only one... (4 Replies)
Discussion started by: ljubayuu
4 Replies

6. UNIX for Dummies Questions & Answers

bridge on linux

Hello. I expirince some problems with bridging, i'm pretty new to that technology I've 2 nic's 1 - wireless rt2500 ra0 canyon cn511 card 2 - e100 intel, ifconfig ra0 up && iwconfig ra0 essid xxx channel x mode managed bring me wireless connection up then i do following: brctl addbr br0... (1 Reply)
Discussion started by: hachik
1 Replies
Login or Register to Ask a Question