From 1030b88acbf9ff6c165292c738a1c054cbe7ecd9 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Tue, 31 May 2022 19:20:27 +1000 Subject: [PATCH] improve -W option --- aircon.sh | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/aircon.sh b/aircon.sh index 8f7843b..3a27ad1 100755 --- a/aircon.sh +++ b/aircon.sh @@ -1298,7 +1298,7 @@ function canping() { else arp -d $ip >/dev/null 2>&1 #ping -c1 -w1 -n -q $ip >/dev/null 2>&1 & - arping -c10 -W0.1 -w2 -C1 -q ${ip} 2>/dev/null + arping -c10 -W0.1 -w3 -C1 -q ${ip} 2>/dev/null sleep 0.3 mac=$(arp -n $ip) mac=$(echo "$mac" | egrep -v "Host|xpired" | awk '{print $2}') @@ -1921,12 +1921,12 @@ elif [[ $showwho -eq 2 ]]; then [[ ${#x} -gt $maxlen ]] && maxlen=$((${#x} + 3)) done # get a list of all devices - TFORMAT="${BOLD}${UNDERLINE}%-${maxlen}s%-16s${PLAIN}\n" - HFORMAT="%-${maxlen}s${GREEN}%-16s${PLAIN}\n" - AFORMAT="%-${maxlen}s${RED}%-16s${PLAIN}\n" + TFORMAT="${BOLD}${UNDERLINE}%-${maxlen}s%-16s%s${PLAIN}\n" + HFORMAT="%-${maxlen}s${GREEN}%-16s${PLAIN}%s\n" + AFORMAT="%-${maxlen}s${RED}%-16s${PLAIN}%s\n" alldevs=$(echo "${ownerhost[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ') echo - printf "$TFORMAT" "Devices" "Availability" + printf "$TFORMAT" "Devices" "Availability" "Zones owned" for x in $alldevs; do if canping ${x}; then thisform="$HFORMAT" @@ -1935,7 +1935,14 @@ elif [[ $showwho -eq 2 ]]; then thisform="$AFORMAT" str="Unavailable" fi - printf "$thisform" "${x}" "$str" + unset mydevs || declare -a mydevs + for i in ${!ownerzone[@]}; do + if [[ ${ownerhost[$i]} == *${x}* ]]; then + mydevs+=("${ownerzone[$i]}") + fi + done + allmydevs=$(echo "${mydevs[@]}" | tr '\n' ' ') + printf "$thisform" "${x}" "$str" "${allmydevs}" done echo exit 0