5

I'm trying to launch Android tethering settings from adb shell. The main purpose of doing so is to enable USB tethering mode by running a shell script. I'm using the following set of commands on my Ubuntu Terminal (12.04):

adb shell
am start -n com.android.settings/.TetherSettings
sleep 7
input tap 162 159
input tap 385 607

This method works fine when the commands are executed one by one, but I'm not able to run them as normal shell script. Please help! Here is the complete script:

#!/bin/sh
adb shell
am start -n com.android.settings/.TetherSettings
sleep 7
input tap 162 159
input tap 385 607

I guess, it can't find the path to adb in my system. I've tried replacing the first line with the actual path to adb tool in SDK directory. That didn't work either. Any work around for this? (Sorry if the question seems silly. I'm really new to bash scripting!)

EDIT: Updated script:-

#!/bin/sh
cd /home/evinish/Documents/Android/adt-bundle-linux-x86_64-20130219/sdk/platform-tools
adb shell "
am start -n com.android.settings/.TetherSettings
sleep 7
input tap 162 159
input tap 385 607
"
3
  • Try replacing #!/bin/sh with #!/usr/bin/env bash. Commented Dec 24, 2013 at 18:23
  • Put pwd as the first line. If you're not in the same directory as adb make sure that you cd into the correct directory Commented Dec 24, 2013 at 18:24
  • Thanks Stephen, but the problem is still there. As proposed by KDEx, I did include a cd command in my script. But still, the output says- "adb not found" Commented Dec 24, 2013 at 18:59

2 Answers 2

14

adb shell opens a shell on your Android device. The subsequent commands are entered in the context of that shell. Add quotes around the remote commands:

adb shell "
am start -n com.android.settings/.TetherSettings
sleep 7
input tap 162 159
input tap 385 607
"
Sign up to request clarification or add additional context in comments.

2 Comments

I don't understand why, as I've already provided full path to adb. Please refer to EDIT section.
You're missing a leading ./ on your ADB command. If adb is not in your path, you have to run it from the install directory. Either cd /home/evinish/Documents/Android/adt-bundle-linux-x86_64-20130219/sdk/platform-tools && ./adb shell or /home/evinish/Documents/Android/adt-bundle-linux-x86_64-20130219/sdk/platform-tools/adb shell.
3

Thanks everybody! I finally solved the problem. Here is the updated script:

    #!/bin/sh
    cd /home/evinish/Documents/Android/adt-bundle-linux-x86_64-20130219/sdk/platform-tools
    ./adb start-server
    ./adb devices
    ./adb shell "
    am start -n com.android.settings/.TetherSettings
    sleep 15
    input tap 162 159
    input tap 385 607
    "
    sleep 10

The only problem was missing "./" before adb.

EDIT: also why not check to see if the server is running first?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.