#!/usr/bin/env bash # ===== Config ===== SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" 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 clear_logs_all.sh -ipfile " exit 1 ;; esac done if [[ -z "$IP_FILE" ]]; then echo "Usage: sh clear_logs_all.sh -ipfile " exit 1 fi # ===== Wi-Fi Check ===== wifi_interface=$(networksetup -listallhardwareports | \ awk '/Wi-Fi|AirPort/{getline; print $2}') current_ssid=$(networksetup -getairportnetwork "$wifi_interface" 2>/dev/null | \ awk -F': ' '{print $2}' | tr '[:upper:]' '[:lower:]') expected_ssid="cloud solutions" if [[ "$current_ssid" != "$expected_ssid" ]]; then echo "โŒ Not connected to required Wi-Fi network: $expected_ssid" echo "๐Ÿ”Œ Current network: ${current_ssid:-Not connected}" exit 1 fi echo "โœ… Connected to correct Wi-Fi: Cloud Solutions" # ===== 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[@]}" # ===== Connect to Devices and Clear Logs ===== 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 "๐Ÿงน Clearing logs on $cleanIP..." adb -s "$cleanIP:5555" shell rm -rf "$LOG_PATH/*" if [[ $? -eq 0 ]]; then echo "โœ… Logs cleared on $cleanIP" else echo "โŒ Failed to clear logs on $cleanIP" fi done echo "โœ… Done! Logs cleared on all devices."