Skip to content

Instantly share code, notes, and snippets.

@lowstz
Forked from xream/MacVPN.sh
Created February 8, 2012 15:22
Show Gist options
  • Save lowstz/1770403 to your computer and use it in GitHub Desktop.
Save lowstz/1770403 to your computer and use it in GitHub Desktop.
Linux openvpn auto reconnect script
#!/bin/bash
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
### Thanks Xream's Work XD
# if you don't have several vpn servers to select, you can comment following line
# and use your openvpn config file name to replace "${host}.ovpn" in while loop.
read -p "Select the host: " host
function getStatus () {
ifconfig | grep $1 && return 1
return 0
}
while [[ 1 ]]; do
getStatus tun0
if [[ $? == 0 ]]; then
echo "openvpn is not connected!"
echo "Reconnecting!"
#Replace your_sudo_password to your real user sudo password.
echo your_sudo_password | sudo -S openvpn --config /home/user/openvpn/${host}.ovpn
sleep 6
fi
sleep 6
done
@pingaan
Copy link

pingaan commented Mar 2, 2019

I have another question though... Is it possible to skip the step on the 9th line? "Select the host: "?
I'd like for the script to run at boot up. Perhaps there is a nother way to launch it at boot up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment