nohangup using ADB shell - android

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

Related

Screenshots with adb from script which is run form macOS application

I'm trying to take a screenshot on an Android-device/emulator, which should be triggered from within an macOS application.
I've created a bash-script - and it works well if I run it from the terminal.
However, when I run it from my macOS application, I get an error when I try to pull the image from the device.
ADB="$1"
DEVICE="$2"
PATH="$3"
FILENAME="$4"
$ADB -s "$DEVICE" shell screencap -p "/sdcard/${FILENAME}"
$ADB -s "$DEVICE" pull "/sdcard/${FILENAME}"
I get the following error:
adb: error: cannot create './EBC34F20-4624-4435-806B-15D844F4540C.png': Read-only file system
Why is it different from when I run it in the terminal? I've tried looking at which user is executing though adb and that all comes back with the same info.
I've removed sandbox and hardened runtime from my macOS app to to avoid it interfering.
It doesn't seem to matter if I change location (not /sdcard) on the emulator either.
I don't know what the actual problem is with the file-system on your device but I would simply avoid using the file-system at all and directly pipe the screenshot to stdout and via adb to your Mac.
Remove the following two lines:
$ADB -s "$DEVICE" shell screencap -p "/sdcard/${FILENAME}"
$ADB -s "$DEVICE" pull "/sdcard/${FILENAME}"
and replace them with this line:
$ADB -s "$DEVICE" exec-out screencap -p > ${FILENAME}
No adb pull and hence no problems with the file-system at all.
The command has been taken from the following answer: https://stackoverflow.com/a/31401447/150978

adb "error device not found" when trying to use 'adb shell' but "adb devices" detects the device

Guys basically I've plugged in a bunch of Android devices to a computer and each of them has adb enabled. I'm running a shell script to push certain files to the devices using the Device Serial Numbers stored in a text file. When I trigger the script the first time it works. if i trigger it again adb throws an error , "error device not found" though the devices are still detected using adb. If i close the terminal and reopen it and run the script it works fine. I plan to eventually automate the script running. How can i stop this from happening.
EDIT: This is the piece of code where the adb shell commands are triggered
cat device_serial | while read line
do
adb -s $line shell
cd /data/
ls
exit
adb -s $line root
adb -s $line push 'stestfile.txt ' /data/
echo "done"
done
I need to look at the script to fix the issue.
But looks like the problem is that the next time you run the script, you are actually in the device's shell instead of your computer's.

Start a process in background from adb shell without attaching the process to the terminal in Android

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

How to run command as background process using ADB?

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.

How to start an android app with valgrind

I've been searching for the last week trying to find an answer to this question.
How do I start an Android app with valgrind? I know I can start an app with the 'am' command, but it starts the app and exits.
I'm writing an app that uses the NDK for native C code, and I need to check it for suspected memory errors.
Edit:
I've learned a little more. You can "wrap" an app with a shell script.
Here's the shell script I'm using:
#!/system/bin/sh
VGPARAMS='--error-limit=no'
export TMPDIR=/data/data/com.starlon.froyvisuals
exec /data/local/Inst/bin/valgrind $VGPARAMS $*
And here's setprop:
adb shell setprop wrap.com.starlon.froyvisuals "logwrapper valgrind"
And here's how I start the app:
adb shell am start -n com.starlon.froyvisuals/.FroyVisuals
I don't think this is right, because I'm not sure where the shell script fits in and I'm not seeing anything in logcat. Any hints?
Edit2:
Oh the shell script is indicated with "setprop" command above. So
adb shell setprop wrap.com.starlon.froyvisuals "logwrapper /data/local/val.sh"
I'm still not seeing anything in logcat.
You can try to clear the logcat first
prompt# adb logcat -c
prompt# adb logcat
You should be able to see the logs coming in once you triggered your application.
am start -a android.intent.action.MAIN -n com.example.hellojni/.HelloJni
I had problems with my shell script and i used this instead.
adb shell setprop wrap.com.example.hellojni "logwrapper /data/local/Inst/bin/valgrind"
You should be able to pass in the parameter right after valgrind
I encountered this problem too. In my situation, I edit the "val.sh" in windows & adb push it to the emulator, but the shell script could not be executed correctly. Then I use a echo "*" > val.sh style to make the "val.sh" and It works well.
So you should first make sure the "val.sh" could be interpreted correctly.

Categories

Resources