'Bash/Pinger/Dual-IF-Ping.sh.example' updaten
This commit is contained in:
99
Bash/Pinger/Dual-IF-Ping.sh.example
Normal file
99
Bash/Pinger/Dual-IF-Ping.sh.example
Normal file
@@ -0,0 +1,99 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Set Parameters
|
||||
domoticzserverip='127.0.0.1:8080'
|
||||
if1='<IP of first if>'
|
||||
IDX1='<Dev1-IDX>'
|
||||
if2='<IP of second if>'
|
||||
IDX2='<Dev2-IDX>'
|
||||
ExtTestServ='<DevStaticIP>'
|
||||
|
||||
echo $$ > /var/log/pid/IntetPing.pid
|
||||
|
||||
while [ 1 ]
|
||||
do
|
||||
# First Attempt
|
||||
#First IF
|
||||
fping -c5 -b 32 -t100 -S $if1 $ExtTestServ > /dev/null 2>&1
|
||||
if [ "$?" = 0 ] ; then
|
||||
device1="On"
|
||||
success1="yes"
|
||||
else
|
||||
success1="no"
|
||||
fi
|
||||
#Second IF
|
||||
fping -c5 -b 32 -t100 -S $if2 $ExtTestServ > /dev/null 2>&1
|
||||
if [ "$?" = 0 ] ; then
|
||||
device2="On"
|
||||
success2="yes"
|
||||
else
|
||||
success2="no"
|
||||
fi
|
||||
|
||||
# Waiting 10 seconds to avoid haning the script
|
||||
if [[ $success1 != 'yes' ]]; then
|
||||
sleep 10
|
||||
fi
|
||||
if [[ $success2 != 'yes' ]]; then
|
||||
sleep 10
|
||||
fi
|
||||
|
||||
# Second network ping attempt
|
||||
#First IF
|
||||
if [[ $success1 != 'yes' ]]; then
|
||||
fping -c5 -b 32 -t100 -S $if1 $ExtTestServ > /dev/null 2>&1
|
||||
if [ "$?" = 0 ] ; then
|
||||
device1="On"
|
||||
success1="yes"
|
||||
else
|
||||
success1="no"
|
||||
fi
|
||||
fi
|
||||
#Second IF
|
||||
if [[ $success2 != 'yes' ]]; then
|
||||
fping -c5 -b 32 -t100 -S $if2 $ExtTestServ > /dev/null 2>&1
|
||||
if [ "$?" = 0 ] ; then
|
||||
device2="On"
|
||||
success2="yes"
|
||||
else
|
||||
success2="no"
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
# If the device is still offline, declare it for processing
|
||||
#First IF
|
||||
if [[ $success1 != 'yes' ]]; then
|
||||
device1="Off"
|
||||
fi
|
||||
#Second IF
|
||||
if [[ $success2 != 'yes' ]]; then
|
||||
device2="Off"
|
||||
fi
|
||||
|
||||
# Check Online / Offline state of Domoticz device
|
||||
domoticzstatus1=$(curl -s "http://"$domoticzserverip"/json.htm?type=devices&rid="$IDX1"" | grep '"Data" :' | awk '{ print $3 }' | sed 's/[!@#\$%",^&*()]//g')
|
||||
|
||||
# Compare ping result to Domoticz device status
|
||||
if [ "$device1" != "$domoticzstatus1" ] ; then
|
||||
if [ "$device1" = On ] ; then
|
||||
curl -s "http://"$domoticzserverip"/json.htm?type=command¶m=switchlight&idx="$IDX1"&switchcmd=On" 2>/dev/null 1>/dev/null
|
||||
else
|
||||
curl -s "http://"$domoticzserverip"/json.htm?type=command¶m=switchlight&idx="$IDX1"&switchcmd=Off" 2>/dev/null 1>/dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
domoticzstatus2=$(curl -s "http://"$domoticzserverip"/json.htm?type=devices&rid="$IDX2"" | grep '"Data" :' | awk '{ print $3 }' | sed 's/[!@#\$%",^&*()]//g')
|
||||
|
||||
# Compare ping result to Domoticz device status
|
||||
if [ "$device2" != "$domoticzstatus2" ] ; then
|
||||
if [ "$device1" = On ] ; then
|
||||
curl -s "http://"$domoticzserverip"/json.htm?type=command¶m=switchlight&idx="$IDX2"&switchcmd=On" 2>/dev/null 1>/dev/null
|
||||
else
|
||||
curl -s "http://"$domoticzserverip"/json.htm?type=command¶m=switchlight&idx="$IDX2"&switchcmd=Off" 2>/dev/null 1>/dev/null
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
sleep 300
|
||||
done
|
||||
Reference in New Issue
Block a user