#!/bin/sh # Sometimes the connection does down and we lose our route to # the VPN. Re-insert the route if it goes down. IP_FMT="[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*" # This route should be the only hard-coded IP address ROUTE=$(ip route | grep "^$IP_FMT via $IP_FMT dev") # OpenVPN might not have started yet. Repeat until route appears while [ -z "$ROUTE" ]; do sleep 1 ROUTE=$(ip route | grep "^$IP_FMT via $IP_FMT dev") done # Loop forever while true; do # Check that the route still exists, add it if it doesn't if ! ip route | grep -q "$ROUTE"; then echo "Fixing routing..." ip route add $ROUTE fi sleep 1 done