Last active
May 4, 2019 23:02
-
-
Save rubo77/dc6a6914119099162e85b1b8d571d9d0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# this script can log the quality of fastd-connections to all gateways | |
# it sets only one gateway active at a time and checks the connection. | |
# add this script as cron script to get a statistic over time | |
COMMUNITY_NAME=ffki; | |
GW_PREFIX=vpn | |
GATEWAYLIST="0 1 2 4 6" | |
PING_IP6=2a01:4f8:171:27a2:0:77:77:254 | |
STATISTIC_LOG_FILE=/tmp/gw_connection_statistic.log | |
for ENABLED in $GATEWAYLIST; do | |
echo uci enable only Gateway $ENABLED | |
for GATEWAY in $GATEWAYLIST; do | |
STATUS=0 | |
if [ $ENABLED == $GATEWAY ]; then | |
STATUS=1 | |
fi | |
uci set fastd.mesh_${GW_PREFIX}_backbone_peer_${COMMUNITY_NAME}_${GW_PREFIX}${GATEWAY}.enabled=${STATUS} | |
done | |
echo force batman-adv to re-elect the gateway | |
batctl gw off | |
batctl gw client 1 | |
# show active gw: | |
# WLAN reset | |
/sbin/wifi | |
/etc/init.d/fastd stop | |
/etc/init.d/fastd start | |
sleep 20 | |
batctl gwl | grep -e "^=>" -e "^\*" | |
echo check ${GW_PREFIX}${ENABLED} ... | |
ping -c 1 -w 2 $PING_IP6 | |
if [ $? == 0 ]; then | |
echo ping OK | |
else | |
echo has no ping connection | |
DATE=$(date '+%Y-%m-%d %H:%M:%S') | |
echo '{"'$DATE'":{"gw":"'$GW_PREFIX$ENABLED'","ping":false}},'>>$STATISTIC_LOG_FILE | |
fi | |
# check TQ | |
TQ=$(batctl gwl | grep -e "^=>" -e "^\*" | awk -F '[()]' '{print $2}' | tr -d " ") | |
if [ $TQ -gt 100 ]; then | |
echo TQ $TQ is OK | |
else | |
echo TQ $TQ is NOT OK | |
DATE=$(date '+%Y-%m-%d %H:%M:%S') | |
echo '{"'$DATE'":{"gw":"'$GW_PREFIX$ENABLED'","tq":"'$TQ'"}},'>>$STATISTIC_LOG_FILE | |
fi | |
done | |
echo reenable all Gateways | |
for GATEWAY in $GATEWAYLIST; do uci set fastd.mesh_${GW_PREFIX}_backbone_peer_${COMMUNITY_NAME}_${GW_PREFIX}${GATEWAY}.enabled=1 ; done | |
# show result | |
for CHECK in $GATEWAYLIST; do uci show fastd.mesh_${GW_PREFIX}_backbone_peer_${COMMUNITY_NAME}_${GW_PREFIX}${CHECK}.enabled ; done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment