-
-
Save lowstz/1770403 to your computer and use it in GitHub Desktop.
Linux openvpn auto reconnect script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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
I worked it out.
For some reason running the script with "sh" ended up in this error while ./ worked just fine. Didn't know there were any differences.
Cheers for a neat script!