I am trying to run logcat in background using adb.
adb shell "logcat -r 2000 -f /data/local/test.log &"
But it does not work. If I do adb shell ps | grep logcat I dont see logcat process running.
Adding nohup seems to work.
adb shell "nohup logcat -r 2000 -f /data/local/test.log &"
If you can't run nohup directly, then you could try this: busybox nohup logcat
BusyBox combines tiny versions of many common UNIX utilities into a single small executable. So it has nohup feature as well and you could use it via busybox if manufacturer turns nohup option on at compile time.
Related
I am trying to do a logcat to a file using adb shell by following command -
adb shell "nohup logcat -f /storage/sdcard0/myLog.txt -v time &"
If I do a ps | grep logcat, I don't see the logcat command. Even I tried to see nohup command, but it is not there. So somehow above command does not work.
However if I perform the command in 2 steps it works fine -
adb shell
nohup logcat -f /storage/sdcard0/myLog.txt -v time &
I can see the process using ps and logcat continues to record to the file even if I disconnect adb shell. Now I would like the first command to work, since I am using python scripts to issue commands via ADB. It is possible to change the python scripts, however I would like to know if I am doing anything wrong in issuing the first command and if it is possible to make it work.
try
adb logcat
not
adb shell logcat
I'm running a jenkins job that starts an avd device and uses calabash-android to run tests against it.
emulator -avd phone
How can I tell when this device is completely started so that I know I can start the tests without getting a device connection error?
I tried
adb wait-for-device
but that won't work because according to the adb docs
"Note that this command does not cause adb to wait until the entire system is fully booted. For that reason, you should not prepend it to other commands that require a fully booted system."
Right now I have a hard sleep, what would be a better way to script this?
Thank you.
I presume you are launching your tests via adb. If so, adb supports wait-for-device to block until the device is available (online).
adb wait-for-device
Okay, figured it out. The command I was looking for was
adb shell getprop sys.boot_completed
The full script for using the avd tool with jenkins looks like this (note: the output is all pumped into a textfile so that it doesn't tie up the script, there's probably a better way to handle this part of it)
Launch the sim
$ANDROID_HOME/tools/emulator -avd phone -gpu on -memory 2500 1>~/test.txt 2>&1 &
Wait for the sim to finish launching
A=$($ANDROID_HOME/platform-tools/adb shell getprop sys.boot_completed | tr -d '\r')
while [ "$A" != "1" ]; do
sleep 2
A=$($ANDROID_HOME/platform-tools/adb shell getprop sys.boot_completed | tr -d '\r')
done
Unlock sim
$ANDROID_HOME/platform-tools/adb shell input keyevent 82 1>~/test.txt 2>&1 &
I have a simple problem.
I want to start/run a program file on an android phone using adb shell.
My Program is in /system/bin folder and has root privileges.
I want to run this program from my command prompt as adb shell runme 3000000 > logs.txt but it should not block the terminal, It should run in background.
I cannot use screen/disown/nohup for my problem as android doesn't have all this.
I tried
adb shell "runme >logs.txt &" but of no use.
When i issue command as
adb shell
# runme 3000000 > logs.txt &
It runs fine, when i exit the terminal/disconnect the device and then connect again to system.
Do adb shell ps | grep runme shows the process is still runnning in background.
Thanks
Busybox has nohup applet which works just fine in Android
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
I have created a script to mount partitions and do some stuff in my Android system. I saved the script as install.sh in the /bin folder of Android.
I want to call the script from ADB, which is itself called from a batch file on Windows, but it needs to be executed as root.
The first solution I tried was to call the script using
adb shell "su -c sh /bin/script.sh"
but it does not work as it gives me a shell access (with root permissions), but nothing is executed.
I also tried to call
adb root "sh /bin/script.sh"
but I got the following error
adbd cannot run as root in production builds
I then tried to write
su -c "command"
for all the commands which need a root access in my script, but I have the same problem.
When I run the script I only obtain a root shell and nothing is executed.
If I use the first solution by hand (e.g. I call adb shell su, then my script), it works. However the whole point is to automate the process, so that adb shell can be called from another script.
Do you have any idea of how I could achieve this ?
Thanks !
This works for me:
Create myscript.bat and put into it (note the single quotes around the commands to be executed in superuser mode):
adb shell "su -c 'command1; command2; command3'"
then run myscript.bat from a DOS shell.
Note: it doesn't appear that the the DOS line continuation character (^) works in this situation. In other words, the following doesn't work for me:
adb shell "su -c '^
command1; ^
command2; ^
command3'"
This results in "Syntax error: Unterminated quoted string"
This works :
adb shell echo command which needs root privileges \| su
If you need redirection:
adb shell echo 'echo anytext > /data/data/aforbiddenfolder/file' \| su
For "copying" a local file to an android path needing root privileges (but alocalfile must not contain '):
cat alocalfile | adb shell echo "echo '`cat`' > /data/data/aforbiddenfolder/file" \| su
If you have a better way (even for su versions which don't have -c), I am interested.
This works for me:
adb shell "su -c ./data/local/tcpdump-arm -s 0 -v -w /data/local/appxpress_dump.pcap"
I am not sure if I provided a solution or asked for a better one.
I wanted to run some 200 command in batch mode to be sent to adb
I followed this approach
adb shell "su -c command ; "
adb shell "su -c command ; "
adb shell "su -c command ; "
adb shell "su -c command ; "
and I saved them in a batch file
This command
adb shell "su -c 'command1; command2; command3'"
will not work beyond a certain max size . It did not work
error: service name too long
but it does not work as it gives me a shell access (with root permissions), but nothing is executed.
How do you know that you are given root permissions? I assume you are attempting to execute the script on a device? Has your device been rooted?
You may need to give execute permissions via chmod to the file.
chmod ugo=rwx /bin/script.sh
It appears that I was using a very simple version of su which did not accept the -c argument.
I copied another su which did work. AndyD is totally right though, so I am accepting his answer instead of mine :)