• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Android Automation Script

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)

pseudocode:

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;
sleep(20)
}

please help thank you
 
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)

pseudocode:

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;
sleep(20)
}

please help thank you


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.
 
Upvote 0
You could try something in C++ maybe?

Code:
#include <iostream>
#include <unistd.h>
#include <time.h>

using namespace std;

int main()
{
    const char* command = "cmd_str"; // The command to be run
    pid_t pid;
    
    while(1)
    {
        for(time_t t = time(NULL) + 1200; time(NULL) < t;) {} // Wait for 1200 seconds (20 mins)
        pid = fork();
        if(pid == 0)
        {
            // in the child, do exec  
            execvp(command, NULL);
        }
        else if(pid != (pid_t) -1)
        {
            // in the parent, now perhaps do wait(pid)
        }
        else
        {
            // still in parent, but there is no child
        }
    }
}
This code will only work on a unix based system.
Change cmd_str to your desired command.
You need to compile it with:
Code:
g++ THEFILENAME.cpp -o looprun
And then run it with:
Code:
./looprun

I hope this helps.
 
Upvote 0
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..
 
Upvote 0

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones