19 May 2019
RPI OpenVPN PIA Connection Check Cron Script
This script follows on from our previous post RPI Deluge Port Forwarding Script
This script will check your OpenVPN connection is still working correctly periodically and if not it will restart the openvpn connection.
It will also automatically update your Private Internet Access (PIA) Port Forwarding.
Please note: This script will only work if you have already created the port forwarding script under /home/pi/ as outlined in the previous blog post
RPI Deluge Port Forwarding Script. It also assumes you are running Deluge Daemon on Raspberry Pi with Open VPN.
- Login to your RPI
- cd /home/pi/
- sudo nano vpncheck.sh
- paste in the following script
#!/bin/bash # HTGSD.com 19/05/2019 #Check Connection - change google.com to whatever address you wish to check count=$( ping -c 3 google.com | grep icmp | grep bytes | wc -l ) if [ $count -eq 0 ] then service openvpn restart echo "VPN down, restarting" sleep 10 #forward pia port to deluged /bin/bash /home/pi/portforward.sh else echo "VPN still working, no action" #forward pia port to deluged /bin/bash /home/pi/portforward.sh fi
- Save the file
- make the file executable
sudo chmod +x vpncheck.sh - check the script works
./vpncheck.sh - If it’s working you should see either:
“VPN down, restarting”
or
“VPN still working, no action” - The above will be followed immediately by the Port Forwarding script updating your Deluge port