Reconnect your openvpn tunnel if packets get lost

Check if your openvpn tunnel is still active and if it’s not reconnect it with this bash script:

#!/bin/sh

# Check vpn-tunnel "tun0" and ping cz.nic if internet connection work
if  [ "$(ping -I tun0 -q -c 1 -W 1 193.17.47.1 | grep '100% packet loss' )" != "" ]; then
        logger -t VPN_Reconnect VPN-Tunnel "tun0" has got no internet connectionection -> restart it
        /etc/init.d/openvpn stop
        sleep 3
        /etc/init.d/openvpn start
else
        logger -t VPN_Reconnect VPN-Tunnel "tun0" is working with internet connection
fi

Thanks to: https://forum.turris.cz/t/guide-openvpn-reconnect-script-daily-restart-with-location-change-server-roulette-client-to-stay-allways-on-luci-vpn-nano-ssh-linux/10949