improve -W option

This commit is contained in:
Rob Pearce 2022-05-31 19:20:27 +10:00
parent 90c2778a13
commit 1030b88acb
1 changed files with 13 additions and 6 deletions

View File

@ -1298,7 +1298,7 @@ function canping() {
else else
arp -d $ip >/dev/null 2>&1 arp -d $ip >/dev/null 2>&1
#ping -c1 -w1 -n -q $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 sleep 0.3
mac=$(arp -n $ip) mac=$(arp -n $ip)
mac=$(echo "$mac" | egrep -v "Host|xpired" | awk '{print $2}') 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)) [[ ${#x} -gt $maxlen ]] && maxlen=$((${#x} + 3))
done done
# get a list of all devices # get a list of all devices
TFORMAT="${BOLD}${UNDERLINE}%-${maxlen}s%-16s${PLAIN}\n" TFORMAT="${BOLD}${UNDERLINE}%-${maxlen}s%-16s%s${PLAIN}\n"
HFORMAT="%-${maxlen}s${GREEN}%-16s${PLAIN}\n" HFORMAT="%-${maxlen}s${GREEN}%-16s${PLAIN}%s\n"
AFORMAT="%-${maxlen}s${RED}%-16s${PLAIN}\n" AFORMAT="%-${maxlen}s${RED}%-16s${PLAIN}%s\n"
alldevs=$(echo "${ownerhost[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ') alldevs=$(echo "${ownerhost[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')
echo echo
printf "$TFORMAT" "Devices" "Availability" printf "$TFORMAT" "Devices" "Availability" "Zones owned"
for x in $alldevs; do for x in $alldevs; do
if canping ${x}; then if canping ${x}; then
thisform="$HFORMAT" thisform="$HFORMAT"
@ -1935,7 +1935,14 @@ elif [[ $showwho -eq 2 ]]; then
thisform="$AFORMAT" thisform="$AFORMAT"
str="Unavailable" str="Unavailable"
fi 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 done
echo echo
exit 0 exit 0