OpenVPN Keep Alive Script

From Michael's Information Zone
Revision as of 08:58, 23 May 2016 by Michael.mast (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
                                                                          
#!/bin/sh

#This script is designed to monitor access to the destination LAN, and ensure a tunnel is always up if needed.
#Written by Michael (TurboAAA) Mast. Please improve on this!

#1. Check if the tunnel is needed.
#2. If it is needed check if there is access to the vpn server.
#3. If there is access to the vpn server, clear any running instances and start a fresh instance.
ping -c 2 <LAN IP> &> /dev/null
A=$?
if [ $A = 0 ]; then
exit 0
elif [ $A = 1 ]; then
ping -c 2 <VPN PUBLIC IP> &> /dev/null
A=$?
if [ $A = 1 ]; then
exit 0
elif [ $A = 0 ]; then
killall openvpn
cd /root/
openvpn --config <OVPN CONFIG FILE>.ovpn --auth-user-pass /root/<VPN Credentials>
fi
fi