This is my idea of what I want to do, simply execute the following commands but instead right after the line "adb shell" it stops, no other command can be triggered, whatever it is.
adb connect 192.168.1.101:5555
adb shell
su
rm /data/system/locksettings.db
rm /data/system/locksettings.db-wal
rm /data/system/locksettings.db-shm
PAUSE
reboot
adb shell command alone with out any extra parameters starts the shell in the interactive mode. Meaning it just sits there waiting for user input indefinitely. Your script never gets past that line.
What you really want is:
adb connect 192.168.1.101:5555
adb shell su 0 rm /data/system/locksettings.db
adb shell su 0 rm /data/system/locksettings.db-wal
adb shell su 0 rm /data/system/locksettings.db-shm
PAUSE
adb reboot
Related
I have my laptop connected to an android phone.
I am doing a task many times, so I wish to write a .bat file to run the commands automatically.
adb shell
cd /sdcard/speech
rm -f *
The bat file only executed adb shell, the rest codes were not executed.
I guess because the it entered the android device so the commands did not run as usual.
One solution was adb shell rm -f -r /sdcard/speech/*
What if there are more and more complicated commands?
Is there a way to do it ?
You can do your job with adb shell "cd /sdcard/speech; rm -f *".
For more complicated jobs, you can put all the commands in a Linux shell script, use adb push command to push the script to your Android device, and run the script using adb shell.
For example, put all the commands in run.sh, then issue:
adb push run.sh /data/local/tmp
adb shell "chmod +x /data/local/tmp/run.sh"
After this you can run your jobs with:
adb shell "/data/local/tmp/run.sh"
You can include the above line in a .bat file.
This question already has answers here:
How to use su command over adb shell?
(7 answers)
Running ADB commands through powershell
(1 answer)
Closed 6 years ago.
i am writing batch script for executing adb commands but while executing "SU" commands only the first commands runs "adb shell" and stops
as the script is typing all the commands very fast and not waiting for previous command to run completely so that next command can be entered into the shell window that is "su" example of code is below
:lckscreen
adb shell
su
rm /data/system/gesture.key
rm /data/system/*.key
exit
exit
pause
goto menu4
i also tried
adb shell & su
but still same Result
shell#Samsung_s4:/ $
please help
Please try
adb shell "su -c 'rm /data/system/gesture.key'"
adb shell "su -c 'rm /data/system/*.key'"
and see the question in How to use su command over adb shell?
You will have to create a separate .txt file containing all the shell commands, in example:
su
mount -o remount,rw /system
mv /system/build.prop /sdcard
Make sure to have put an "enter" at the bottom to execute the last command. Now, in the bat file, where you'd normally put adb shell etc. Put adb shell > nameofyourtxt.txt.
If the only command you want to execute is "su", you can do adb shell su.
I want to type multiple adb shell commands in one line, for example, i want to type adb shell and su and cd sys together. i tried to connect them with && and & bzw.adb shell && su && cd sys, but it seems like not work with adb commands, but works with windows commands. does anybody knows what is the problem?
Sovled by myself adb shell "su -c 'cd sys'"
I'm using an Android-x86 vm running in vmware fusion for some testing purposes. I am pushing files to it via adb push, however, every time I uninstall and reinstall the app, I have to execute the following:
adb shell
su
chmod 777 /my/path
exit
exit
I need to be able to script out this entire process but I'm not sure how I can manage the chmod process via some sort of script. I tried doing something like
adb shell am chmod 777 /my/path
But that doesn't work. I thought it would because I can do
adb shell am start ...
I also tried:
adb shell "su && chmod 777 /my/path && exit && exit"
which actually works, but doesn't exit the shell process. So any advice is much appreciated.
You can pass commands to adb shell, as you mentioned, though it works better if you surround the command in quotes.
Likewise, you can pass commands to the 'su' command using the -c argument. Add all of this together and it should do what you want in a nice one-liner!
adb shell "su -c 'chmod 777 /my/path'"
One problem with ADB is that you need multiple commands to get things done.
For example:
adb shell
su
cp /data/local/x /data/local/y
exit
adb pull /data/local/y
Can this be done using python popen and os-system? Tried the example below without success..
print 'Starting emulator...'
subprocess.Popen(['emulator', '-avd', 'testavd'])
os.system('adb wait-for-device')
os.system('Perform whatever adb commands you need')
Any pointers?
You can simply do:
adb shell su -c cp /data/local/x /data/local/y
adb pull /data/local/y
or, if you want to run more than one command (only Linux & OSX):
adb shell <<EOF
ls
date
cat /proc/version
exit
EOF