1. Download the #1 Android News App:   EarlyBird - News for Android
    Dismiss Notice

Android Automation Script

Last Updated:

  1. CoopDeveloper

    CoopDeveloper New Member

    Hi guys, i need to automate the following process but i do not know how, any tip on creating this is appreciated.

    in ADB SHELL, (say the command I want to execute is cmd_str)


    execute cmd_str every 20 minutes

    how can i write a script that can be run in adb shell that does the above?

    if what i wrote above is not clear, here it is again

    for ( ; ; ) {
    execute cmd_str;

    please help thank you

  2. jonbonazza

    jonbonazza Well-Known Member

    Shell language is NOT a programming language. it is a command line language, therefore you cannot execute things like loops, etc... It is meant to execute commands one line at a time (hence the name command line). Unfortunately, there is no way to do what you want automatically.
  3. Wolfy87

    Wolfy87 New Member

    You could try something in C++ maybe?

    Code (Text):
    2. #include <iostream>
    3. #include <unistd.h>
    4. #include <time.h>
    6. using namespace std;
    8. int main()
    9. {
    10.     const char* command = "cmd_str"; // The command to be run
    11.     pid_t pid;
    13.     while(1)
    14.     {
    15.         for(time_t t = time(NULL) + 1200; time(NULL) < t;) {} // Wait for 1200 seconds (20 mins)
    16.         pid = fork();
    17.         if(pid == 0)
    18.         {
    19.             // in the child, do exec  
    20.             execvp(command, NULL);
    21.         }
    22.         else if(pid != (pid_t) -1)
    23.         {
    24.             // in the parent, now perhaps do wait(pid)
    25.         }
    26.         else
    27.         {
    28.             // still in parent, but there is no child
    29.         }
    30.     }
    31. }
    This code will only work on a unix based system.
    Change cmd_str to your desired command.
    You need to compile it with:
    Code (Text):
    1. g++ THEFILENAME.cpp -o looprun
    And then run it with:
    Code (Text):
    1. ./looprun
    I hope this helps.
  4. hemk.rm

    hemk.rm New Member

    If there is no hard requirement, for you to run the script in the adb shell prompt, then you can just write a perl script and execute it on the windows.

    Basically, you are running ur perl script on windows machine. Your windows machine and device are connected using an usb cable.
    You can write, what ever you want in the perl script.
    You can invoke an adb command as system("adb shell ls "), so forth..

Share This Page