From 31409d3ffde80f378b4755304e1e022f19ecbed8 Mon Sep 17 00:00:00 2001 From: Bram Prieshof Date: Fri, 5 Jun 2020 01:18:15 +0000 Subject: [PATCH] 'Bash/Pinger/Dual-IF-Ping.sh.examp'' toevoegen --- Bash/Pinger/Dual-IF-Ping.sh.examp' | 99 ++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Bash/Pinger/Dual-IF-Ping.sh.examp' diff --git a/Bash/Pinger/Dual-IF-Ping.sh.examp' b/Bash/Pinger/Dual-IF-Ping.sh.examp' new file mode 100644 index 0000000..a0b7e05 --- /dev/null +++ b/Bash/Pinger/Dual-IF-Ping.sh.examp' @@ -0,0 +1,99 @@ +#!/bin/bash + +# Set Parameters +domoticzserverip='127.0.0.1:8080' +if1='' +IDX1='' +if2='' +IDX2='' +ExtTestServ='' + +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 \ No newline at end of file