Linux script to check VPN connectivity
I wonder if any Linux gurus could help me out here.
I'm using Ubuntu and I have it setup that it connects to PIA and automatically connects to one of the servers and will ONLY connect to the VPN.
The problem I have which seems to occur alot more recently is that after a period of time ( days/weeks even months) the VPN will say it is connected still but there will be no internet connectivity. I will have to manually disconnect / reconnect the VPN to restore functionality.
As this is a machine which is set aside it can be a week or so before I realise that it has lost internet.
Is there something out there I could run in the background which could periodically check that I still have an internet connection ( like ping out to google or somethng) and if not automatically disable / enable my network connection??
Thanks in advance
I'm using Ubuntu and I have it setup that it connects to PIA and automatically connects to one of the servers and will ONLY connect to the VPN.
The problem I have which seems to occur alot more recently is that after a period of time ( days/weeks even months) the VPN will say it is connected still but there will be no internet connectivity. I will have to manually disconnect / reconnect the VPN to restore functionality.
As this is a machine which is set aside it can be a week or so before I realise that it has lost internet.
Is there something out there I could run in the background which could periodically check that I still have an internet connection ( like ping out to google or somethng) and if not automatically disable / enable my network connection??
Thanks in advance
Comments
#!/bin/bash
COUNT=$(curl -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/534.30 (KHTML, like Gecko) Chrome/12.0.742.112 Safari/534.30" https://www.privateinternetaccess.com/pages/whats-my-ip/|grep -c "You are protected by PIA")
if [ $COUNT > 0 ]
then
echo "YOU ARE CONNECTED TO VPN"
else
echo "YOU ARE NOT CONNECTED TO VPN"
pkill deluge
fi
if (( $COUNT > 0 ))
i.e replace [ ] with (())