VPN Auto Connect

Categories: Scripts

A quick shell script to auto-connect openvpn to your VPN. You just need to ensure that your autologin configured .ovpn file is saved in /etc/openvpn and rename replaceme.ovpn in the script to the name of your config file.

echo "#!/bin/bash" > /sbin/vpncheck
echo "" >> /sbin/vpncheck
echo "if ! /sbin/ifconfig tun0 | grep -q "00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00"" >> /sbin/vpncheck
echo "then" >> /sbin/vpncheck
echo "        /usr/sbin/openvpn /etc/openvpn/REPLACEME.ovpn" >> /sbin/vpncheck
echo "        service ssh restart" >> /sbin/vpncheck
echo "fi" >> /sbin/vpncheck
chmod +x /sbin/vpncheck
echo '* * * * * root /sbin/vpncheck >/dev/null 2>&1' >> /etc/cron.d/vpncheck
«
»