-
-
Save lowstz/1770403 to your computer and use it in GitHub Desktop.
#!/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 |
where the username should be enterd?
@SajadAbasi, in *.ovpn
file you can add entry
auth-user-pass up.txt
and in file up.txt
:
your_username
your_password
Can anybody state out the procedure how to do it?
I have this error when execute the script on my/path/directory,
utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000
inet6 fe80::11b6:ff42:907:ed7e%utun0 prefixlen 64 scopeid 0xb
utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000
inet6 fe80::11b6:ff42:907:ed7e%utun0 prefixlen 64 scopeid 0xb
utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000
inet6 fe80::11b6:ff42:907:ed7e%utun0 prefixlen 64 scopeid 0xb
And other issue is not clear of the scripte
#Replace your_sudo_password to your real user sudo password.
Thanks
Finally it is fixed!
This is because of the getStatus command not work on my MBP. I comment it out then everything work.
Add the script directory /path/to/my/myscript.sh into the /usr/home~ .profile and .bash_profile and than logout & login again.
Hey!
I keep getting the error message:
$/home/pi/.VPN/auto-ovpn2.sh: 6: /home/pi/.VPN/auto-ovpn2.sh: Syntax error: "(" unexpected
The script seems to output an error already on the 11th row. What could I be doing wrong? When selecting host on the 9th row, what should I pick btw? Simply "host"?
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!
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?
You can achieve the same by adding
keepalive 10 120
to your conf, as stated in the docs.