Ping Watchdog for Strongswan

#!/bin/bash
HOST=$1 ##Host IP at endpoint to test
ConnName=$2 ##StrongSwan connection name to call
OfflineCount=1
while [ $OfflineCount -gt 0 ]
do
echo loop $OfflineCount
ping=$(ping -c 1 -w 2 $HOST | grep bytes | wc -l)
if [[ $ping -gt 1 ]];then
echo "HOST ONLINE"
logger "[vpnwatchdog] host $HOST online"
OfflineCount=0
exit
else
echo "HOST OFFLINE"
let OfflineCount++
sleep 1
fi
if [[ $OfflineCount -gt 9 ]];then
logger "[vpnwatchdog] host $HOST timeout reached. Restarting VPN..."
echo "OFFLINE LIMIT REACHED"
sudo strongswan down $ConnName
sudo strongswan up $ConnName
exit
fi
done

Leave a Reply

Your e-mail address will not be published. Required fields are marked *