Last active
March 26, 2023 07:18
-
-
Save dhavaln/46a2c236ea1231dcdfa6c11d551d5193 to your computer and use it in GitHub Desktop.
Download ADB Logs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This line may have a performance impact on the Android device, due to an increase in the overall log buffer size.