From 2b3313d0859cf044e4a7dd5a1ccb2745591e7be7 2019-05-27 17:46:12 From: fantawams Date: 2019-05-27 17:46:12 Subject: [PATCH] updated the script for better handling --- diff --git a/ffluxbot/ff_reachable_check_lists.sh b/ffluxbot/ff_reachable_check_lists.sh index 8f87cd1e9186cc2534d6b1a33910539191c203b5..31f158fa0ec8aaf074ffccbdfa6cc241f36b256d 100755 --- a/ffluxbot/ff_reachable_check_lists.sh +++ b/ffluxbot/ff_reachable_check_lists.sh @@ -1,30 +1,66 @@ #!/bin/bash + +# variables timeout=2000 pingcount=2 interval=50 +pathtoscript=/home/scripts +delaytime=15 + +#first check out of 3 +#empty empty old list +cat /dev/null > nodes_NOK.txt +# do the check while IFS= read -r ip; do - node_name=$(awk "/^$ip/ "'{print $NF}' /home/scripts/ffluxbot/FFnodes.txt) - - if fping6 -c $pingcount -t $timeout -i $interval "$ip" &>/dev/null; then - echo "$ip is Pingable" - else - echo "$ip Not Pingable" - echo "$node_name" - sleep 5 + #get node names + node_name=$(awk "/^$ip/ "'{print $NF}' $pathtoscript/ffluxbot/FFnodes.txt) + #Is node IP pingable if fping6 -c $pingcount -t $timeout -i $interval "$ip" &>/dev/null; then - echo "$ip is Pingable" - else - echo "$ip Not Pingable" - echo "$node_name" - sleep 5 - if fping6 -c $pingcount -t $timeout -i $interval "$ip" &>/dev/null; then - echo "$ip is Pingable" - else - echo "$ip Not Pingable" - echo "$node_name" - python3 /home/scripts/ffluxbot/send_client.py -d -j JIDofthebot -p passwordofthebot -t fantawams@c3l.lu -m "FreiFunk node $node_name with $ip is not reachable" - python3 /home/scripts/ffluxbot/send_client.py -d -j JIDofthebot -p passwordofthebot -t orimpe@c3l.lu -m "FreiFunk node $node_name with $ip is not reachable" - fi + #do this + echo "$node_name is Pingable" + else + #Els do this + echo "$node_name Not Pingable" + echo "$ip" >> nodes_NOK.txt + fi +done <$pathtoscript/ffluxbot/iplist.txt +echo Â"Check 1 done" +sleep $delaytime +echo Â"Start Check 2" +cat /dev/null > nodes_NOK2.txt + +#second check out of 3 +while IFS= read -r ip2; do + node_name=$(awk "/^$ip2/ "'{print $NF}' $pathtoscript/ffluxbot/FFnodes.txt) + + if fping6 -c $pingcount -t $timeout -i $interval "$ip2" &>/dev/null; then + echo "$node_name is Pingable" + else + echo "$node_name Not Pingable" + echo "$ip2" >> nodes_NOK2.txt fi -fi -done nodes_NOK3.txt + +#last check out of 3 +while IFS= read -r ip3; do + node_name=$(awk "/^$ip3/ "'{print $NF}' $pathtoscript/ffluxbot/FFnodes.txt) + + if fping6 -c $pingcount -t $timeout -i $interval "$ip3" &>/dev/null; then + echo "$node_name is Pingable" + else + echo "$node_name Not Pingable" + echo "$node_name with IPV6 $ip3 is not reachable" >> nodes_NOK3.txt + fi +done <$pathtoscript/ffluxbot/nodes_NOK2.txt +echo "Check 3 done" + +# prepare Text message +textmessage=$(cat nodes_NOK3.txt) +echo "$textmessage" + +python3 $pathtoscript/ffluxbot/send_client.py -d -j BotJID -p Botpassword -t fantawams@c3l.lu -m "$textmessage" +python3 $pathtoscript/ffluxbot/send_client.py -d -j BotJID -p Botpassword -t orimpe@c3l.lu -m "$textmessage"