You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.0 KiB
Bash
70 lines
2.0 KiB
Bash
|
|
#!/usr/bin/env bash
|
|
|
|
# ===== Config =====
|
|
LOG_DIR="$(pwd)/logs"
|
|
LOG_PATH="/storage/emulated/0/Android/data/com.example.hmg_qline.hmg_qline/files/logs"
|
|
|
|
# ===== Parse Arguments =====
|
|
while [[ $# -gt 0 ]]; do
|
|
key="$1"
|
|
case $key in
|
|
-ip)
|
|
DEVICE_IP="$2"
|
|
shift # past argument
|
|
shift # past value
|
|
;;
|
|
*)
|
|
echo "Unknown option: $1"
|
|
echo "Usage: sh extract_logs.sh -ip <device_ip:port>"
|
|
exit 1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [[ -z "$DEVICE_IP" ]]; then
|
|
echo "Usage: sh extract_logs.sh -ip <device_ip:port>"
|
|
exit 1
|
|
fi
|
|
|
|
# ===== Create Local Log Directory =====
|
|
mkdir -p "$LOG_DIR"
|
|
|
|
# ===== Connect to Device =====
|
|
cleanIP="${DEVICE_IP%%:*}" # strip port if exists
|
|
echo "🔌 Connecting to $cleanIP..."
|
|
output=$(adb connect "$cleanIP:5555" 2>&1)
|
|
if [[ "$output" == *connected* ]]; then
|
|
echo "✅ Connected to $cleanIP"
|
|
else
|
|
echo "❌ Failed to connect to $cleanIP: $output"
|
|
exit 1
|
|
fi
|
|
|
|
# ===== Check if Device is Available =====
|
|
if ! adb -s "$DEVICE_IP" get-state >/dev/null 2>&1; then
|
|
echo "❌ Device $DEVICE_IP is not available via ADB"
|
|
exit 1
|
|
fi
|
|
|
|
# ===== Check if Log Directory Exists on Device =====
|
|
echo "📁 Checking if log directory exists on device..."
|
|
if ! adb -s "$DEVICE_IP" shell "test -d '$LOG_PATH'" 2>/dev/null; then
|
|
echo "❌ Log directory not found on device: $LOG_PATH"
|
|
echo "💡 Available directories in Android/data/com.example.hmg_qline.hmg_qline/files/:"
|
|
adb -s "$DEVICE_IP" shell "ls -la /storage/emulated/0/Android/data/com.example.hmg_qline.hmg_qline/files/" 2>/dev/null || echo "❌ Could not list files directory"
|
|
exit 1
|
|
fi
|
|
|
|
# ===== List Log Files =====
|
|
echo "📋 Listing log files on device..."
|
|
adb -s "$DEVICE_IP" shell "ls -la '$LOG_PATH'"
|
|
|
|
# ===== Extract Logs =====
|
|
echo "📥 Extracting logs from $DEVICE_IP..."
|
|
if adb -s "$DEVICE_IP" pull "$LOG_PATH" "$LOG_DIR"; then
|
|
echo "✅ Logs extracted successfully from $DEVICE_IP to $LOG_DIR"
|
|
else
|
|
echo "❌ Failed to extract logs from $DEVICE_IP"
|
|
exit 1
|
|
fi |