I am using a VPN server on a vps. The VPN service I use can of course go down for a few minutes or maybe even hours by accident or whatever. If it happens, I would like to quickly reconnect to another vpn-server with the command "vpnapp reconnect".
Does anyone know how to do a bash script I will run every minute via cronjob that:
- Pings google.com
2A) If it can be reached, do nothing
2B) If it cannot be reached – which would mean the vpn server is down/not working – enter terminal command "vpnapp reconnect" which will make the vpn application reconnect to next available server they offer.
Would be so thankful if anyone could help me. I have ZERO programming knowledge. To me this is pure science.
Thanks in advance.
Oski
2
Answers
Can it be this simple?
So if 4 packages are received, meaning google.com can be reached it will just exit the bash script.
if not, then it will just enter vpnapp reconnect as a command in the terminal... reconnecting the vpn.
or does it need to be "vpnapp reconnect" embedded in "?
Lol i am so weak at this. I really dont trust my own suggestion anyway so would love to hear a real programmer speak. Thanks!!
You don’t need a bash script, you can just add this cron job (with
crontab -e
):* * * * *
Run the command every minute.ping -c2 google.com
Send 2 pings to google.com.|| vpnapp reconnect
mean that if ping failled it will runvpnapp reconnect