From 3f31ede396477fa046a070f63e00f2bae15be737 Mon Sep 17 00:00:00 2001 From: Rob Pearce Date: Tue, 28 Jun 2022 17:16:21 +1000 Subject: [PATCH] Another fix for zone owner detection --- aircon.sh | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/aircon.sh b/aircon.sh index 1335170..b216eaf 100755 --- a/aircon.sh +++ b/aircon.sh @@ -122,6 +122,7 @@ function getzoneaction() { # populates zproblem[] and zaction[] idx=$1 profile "getzoneaction for idx ${zname[$idx]}" + [[ $robtest -eq 1 ]] && echo "getzoneaction zone ${zname[$idx]}" thisaction="n/a" if [[ ${zignore[$idx]} -eq 1 ]]; then problem="n/a" @@ -129,17 +130,17 @@ function getzoneaction() { # populates zproblem[] and zaction[] else if [[ -z ${zowner[$idx]} ]]; then pingok=1 + #[[ $robtest -eq 1 ]] && echo " empty owner so no ping " elif canping ${zowner[$idx]}; then + #[[ $robtest -eq 1 ]] && echo " canping returned ok" pingok=1 else + #[[ $robtest -eq 1 ]] && echo " canping returned fail" pingok=0 - thisperfect=1 + thisperfect=0 fi fv=$(getforcevent ${zname[$idx]}) - -if [[ $robtest -eq 1 ]]; then - echo "canping zone ${zname[$idx]} is: $pingok" -fi + [[ $robtest -eq 1 ]] && echo " canping zone ${zname[$idx]} is: $pingok" donearby=0 @@ -1323,7 +1324,13 @@ function canping() { local n hname ip db host success=0 mac local os arprv arpres os=$(uname -s) - db=0 + db=1 + if [[ $db -eq 1 ]]; then + info "canping() for:" + for host in $*; do + info " - '${host}'" + done + fi # get ip and clear arp n=0 for host in $*; do @@ -1336,16 +1343,17 @@ function canping() { if [[ -n ${ip[$n]} ]]; then arp -d ${ip[$n]} >/dev/null 2>&1 fi + n=$((n + 1)) done # send new arp req for n in ${!ip[@]}; do if [[ -n ${ip[$n]} ]]; then - if [[ -e $ARPING ]]; then - ${ARPING} -c10 -W0.2 -w4 -C1 -q ${ip[$n]} 2>/dev/null & - else - ping -c 1 -w 1 -q ${ip[$n]} 2>/dev/null & - fi + if [[ -e $ARPING ]]; then + ${ARPING} -c10 -W0.2 -w4 -C1 -q ${ip[$n]} 2>/dev/null & + else + ping -c 1 -w 1 -q ${ip[$n]} 2>/dev/null & + fi fi done @@ -1355,13 +1363,16 @@ function canping() { # now check entries for n in ${!ip[@]}; do + [[ $db -eq 1 ]] && info " recheck ${hname[$n]} (${ip[$n]})" if [[ -n ${ip[$n]} ]]; then arpres=$(arp -n ${ip[$n]} 2>/dev/null) - arprv=$? + arprv=$? mac=$(echo "$arpres" | egrep -v "Host|xpired" | awk '{print $2}') [[ $mac == *:* ]] && success=1 fi - [[ $db -eq 1 ]] && info "canping() ${hname[$n]} (${ip[$n]}) is $success - mac=$mac" + [[ $db -eq 1 ]] && info " ${hname[$n]} (${ip[$n]}) mac is mac=$mac" + [[ $db -eq 1 ]] && info "canping() ${hname[$n]} (${ip[$n]}) is $success" + if [[ $success -eq 1 ]]; then return 0 fi @@ -1947,12 +1958,12 @@ fi #done #wait -if [[ $robtest -eq 1 ]]; then - for x in ${!zname[@]}; do - echo "zone ${zname[$x]} owner is [${zowner[$x]}]" - done - exit 1 -fi +#if [[ $robtest -eq 1 ]]; then +# for x in ${!zname[@]}; do +# echo "zone ${zname[$x]} owner is [${zowner[$x]}]" +# done +# exit 1 +#fi if [[ $showwho -eq 1 ]]; then # get max phone name length @@ -1994,7 +2005,7 @@ elif [[ $showwho -eq 2 ]]; then n=0 for x in $alldevs; do - canping ${x} >/dev/null 2>&1 + canping ${x} 2>&1 pingres[$n]=$? n=$((n + 1)) done