Skip to content

Instantly share code, notes, and snippets.

@dhavaln
Last active March 26, 2023 07:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhavaln/46a2c236ea1231dcdfa6c11d551d5193 to your computer and use it in GitHub Desktop.
Save dhavaln/46a2c236ea1231dcdfa6c11d551d5193 to your computer and use it in GitHub Desktop.
Download ADB Logs
#!/bin/bash
echo "Usage: adb-logger <device ip:port> <file path with name>"
echo "Example: ./adb-logger 192.168.0.237:5555 ./device-logs/192.168.0.237"
waittime=60
device=$1
while :
do
timestamp=$(date +%F_%H-%M)
if adb connect $1 | grep -q 'connected'; then
echo "**** ${timestamp}|${device}|Connected ****"
adb -s $1 logcat -G 16M
adb -s $1 logcat -b all -d > $2-tmp
if [ $? -eq 0 ]; then
filesize=$(wc -c $2-tmp | awk '{print $1}')
echo "Log file size, ${filesize}"
if [ "`head -n 2 $2-tmp`" == "`head -n 2 $2`" ]; then
mv $2-tmp $2
else
echo "Change in file size. Keeping last file as snapshot"
mv $2 $2-$(date +%F_%H-%M)
mv $2-tmp $2
fi
echo "Logs downloaded successfully."
fi
else
echo "**** ${timestamp}|${device}|Failed to Connect ****"
fi
sleep $waittime
done
@dhavaln
Copy link
Author

dhavaln commented Mar 26, 2023

This line may have a performance impact on the Android device, due to an increase in the overall log buffer size.

adb -s $1 logcat -G 16M

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment