Add -W option to check availablity of devices rather than 'people' (since a person can have multiple devices associated)
Delete ARP entries before availability check.
This commit is contained in:
parent
c4c88988c9
commit
7a5452ddfa
43
aircon.sh
43
aircon.sh
|
@ -69,7 +69,8 @@ function usage() {
|
||||||
echo " -s Validate config file then exit."
|
echo " -s Validate config file then exit."
|
||||||
echo " -S[H] Show configured rules in human-readable format"
|
echo " -S[H] Show configured rules in human-readable format"
|
||||||
echo " (HTML if -H given, otherwise ANSI)."
|
echo " (HTML if -H given, otherwise ANSI)."
|
||||||
echo " -w List which zone owners' devices are available then exit."
|
echo " -w List which people are available then exit."
|
||||||
|
echo " -W List zone owners' devices are available then exit."
|
||||||
echo " -t num Specify degrees below min temperature before taking action."
|
echo " -t num Specify degrees below min temperature before taking action."
|
||||||
echo " -T num Specify degrees above max temperature before taking action."
|
echo " -T num Specify degrees above max temperature before taking action."
|
||||||
echo " -y Actually run commands/db inserts. By default, commands are just displayed."
|
echo " -y Actually run commands/db inserts. By default, commands are just displayed."
|
||||||
|
@ -1173,9 +1174,9 @@ function canping() {
|
||||||
if [[ -z $ip ]]; then
|
if [[ -z $ip ]]; then
|
||||||
thisrv=1
|
thisrv=1
|
||||||
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 &
|
||||||
#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}')
|
||||||
[[ $mac == *:* ]] && thisrv=0 || thisrv=1
|
[[ $mac == *:* ]] && thisrv=0 || thisrv=1
|
||||||
|
@ -1550,7 +1551,7 @@ cronmode=0
|
||||||
logmode=0 #0=none, 1=csv_file, 2=local influxdb
|
logmode=0 #0=none, 1=csv_file, 2=local influxdb
|
||||||
influxdb=""
|
influxdb=""
|
||||||
influxhost="127.0.0.1"
|
influxhost="127.0.0.1"
|
||||||
showwho=0
|
showwho=0 # 1 = show people, 2 = show owners
|
||||||
limit=$DEFAULTLIMIT
|
limit=$DEFAULTLIMIT
|
||||||
profiler=0
|
profiler=0
|
||||||
csvfile="$DEFAULT_CSVFILE"
|
csvfile="$DEFAULT_CSVFILE"
|
||||||
|
@ -1574,7 +1575,7 @@ fi
|
||||||
|
|
||||||
ALLARGS="$ALLARGS $*"
|
ALLARGS="$ALLARGS $*"
|
||||||
|
|
||||||
optstring="A:cD:f:hHi:I:k:l:Lo:pmsSt:T:wx:y"
|
optstring="A:cD:f:hHi:I:k:l:Lo:pmsSt:T:wWx:y"
|
||||||
while getopts "$optstring" i $ALLARGS; do
|
while getopts "$optstring" i $ALLARGS; do
|
||||||
case "$i" in
|
case "$i" in
|
||||||
h)
|
h)
|
||||||
|
@ -1640,6 +1641,9 @@ while getopts "$optstring" i $ALLARGS; do
|
||||||
w)
|
w)
|
||||||
showwho=1
|
showwho=1
|
||||||
;;
|
;;
|
||||||
|
W)
|
||||||
|
showwho=2
|
||||||
|
;;
|
||||||
x)
|
x)
|
||||||
MYAIR="${OPTARG}"
|
MYAIR="${OPTARG}"
|
||||||
;;
|
;;
|
||||||
|
@ -1679,7 +1683,7 @@ else
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $showwho -ne 1 ]]; then
|
if [[ $showwho -eq 0 ]]; then
|
||||||
if [[ -z $MYAIR ]]; then
|
if [[ -z $MYAIR ]]; then
|
||||||
MYAIR=$(which myair)
|
MYAIR=$(which myair)
|
||||||
if [[ $? -ne 0 ]]; then
|
if [[ $? -ne 0 ]]; then
|
||||||
|
@ -1724,6 +1728,31 @@ if [[ $showwho -eq 1 ]]; then
|
||||||
done
|
done
|
||||||
echo
|
echo
|
||||||
exit 0
|
exit 0
|
||||||
|
elif [[ $showwho -eq 2 ]]; then
|
||||||
|
# get max device hostname length
|
||||||
|
maxlen=1
|
||||||
|
for x in ${ownerhost[@]}; do
|
||||||
|
[[ ${#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"
|
||||||
|
alldevs=$(echo "${ownerhost[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' ')
|
||||||
|
echo
|
||||||
|
printf "$TFORMAT" "Devices" "Availability"
|
||||||
|
for x in $alldevs; do
|
||||||
|
if canping "${x}"; then
|
||||||
|
thisform="$HFORMAT"
|
||||||
|
str="Available"
|
||||||
|
else
|
||||||
|
thisform="$AFORMAT"
|
||||||
|
str="Unavailable"
|
||||||
|
fi
|
||||||
|
printf "$thisform" "${x}" "$str"
|
||||||
|
done
|
||||||
|
echo
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue