Changeset - 2b3313d0859c
[Not reviewed]
0 1 0
Max Wahl (Fantawams) - 6 years ago 2019-05-27 17:46:12
fantawams@c3l.lu
updated the script for better handling
1 file changed with 56 insertions and 20 deletions:
0 comments (0 inline, 0 general)
ffluxbot/ff_reachable_check_lists.sh
Show inline comments
 
#!/bin/bash
 

	
 
# variables
 
timeout=2000
 
pingcount=2
 
interval=50
 
while IFS= read -r ip; do
 
    node_name=$(awk "/^$ip/ "'{print $NF}' /home/scripts/ffluxbot/FFnodes.txt)
 
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
 
	#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"
 
        	sleep 5
 
		if fping6 -c $pingcount -t $timeout -i $interval "$ip" &>/dev/null; then
 
        		echo "$ip is Pingable"
 
		#do this
 
		echo "$node_name 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"
 
		#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
 
done <$pathtoscript/ffluxbot/nodes_NOK.txt
 
echo "Check 2 done"
 
sleep $delaytime
 
echo  "Start Check 3"
 
cat /dev/null > 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 </home/scripts/ffluxbot/iplist.txt
 
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"
0 comments (0 inline, 0 general)