#!/bin/bash set -u DEVICES_LIST="$(adb devices -l)" echo "${DEVICES_LIST}" LOG_ROOT="log_capture/session_stats/" CLEAN_LOGS="no" while true; do yn="" read -rp "clean logs on device after fetch? [Y/n] " yn yn="${yn,,}" case "${yn}" in y|yes) CLEAN_LOGS="yes" break ;; n|no) break ;; "") CLEAN_LOGS="yes" break ;; *) echo "answer Y(es) or N(o) (y/n or yes/no)" ;; esac done echo "Known devices list:" echo "${DEVICES_LIST}" while IFS= read -r DEV; do [[ -z "${DEV}" ]] && continue [[ "${DEV}" == List* ]] && continue SERIAL="$(awk '{print $1}' <<<"${DEV}")" STATE="$(awk '{print $2}' <<<"${DEV}")" [[ "${STATE}" != "device" ]] && continue LOG_PATH="${LOG_ROOT}/${SERIAL}/" echo "------------ dumping in ${LOG_PATH}" mkdir -p "${LOG_PATH}" mapfile -t FILES < <(adb -s "${SERIAL}" shell run-as com.foxx.androidcast ls files/session_stats/ "${LOG_PATH}/${f}" if [[ "${CLEAN_LOGS}" == "yes" ]]; then adb -s "${SERIAL}" shell run-as com.foxx.androidcast rm -f "files/session_stats/${f}"