#!/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 -ipfile) IP_FILE="$2" shift # past argument shift # past value ;; *) echo "Unknown option: $1" echo "Usage: sh extract_all_logs.sh -ipfile " exit 1 ;; esac done if [[ -z "$IP_FILE" ]]; then echo "Usage: sh extract_all_logs.sh -ipfile " exit 1 fi # ===== Read IPs ===== if [[ ! -f "$IP_FILE" ]]; then echo "❌ IP file not found at $IP_FILE" exit 1 fi ipList=() while IFS= read -r line; do [[ -n "$line" ]] && ipList+=("$line") done < "$IP_FILE" if [[ ${#ipList[@]} -eq 0 ]]; then echo "❌ No IPs found in file" exit 1 fi echo "✅ Found ${#ipList[@]} IPs" printf '%s\n' "${ipList[@]}" # ===== Extract Logs from All Devices ===== for ip in "${ipList[@]}"; do cleanIP="${ip%%:*}" 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" continue fi echo "📥 Extracting logs from $cleanIP..." adb -s "$cleanIP:5555" shell ls "$LOG_PATH" adb -s "$cleanIP:5555" pull "$LOG_PATH" "$LOG_DIR" done echo "✅ Done! Logs extracted from all devices."