- Use full path in
setcommand - run
screenin detached mode - use a
case ... esacconstruct to make a start/stop script.
#!/bin/bash
case "$1" in
start)
screen -ls | grep -w vpn \
&& { echo "Vpn already connected"; curl ifconfig.co; break; }
set -- /etc/openvpn/ovpn_tcp/*.nordvpn.com.tcp.ovpn
shift $(( RANDOM % $# ))
screen -S vpn -dm openvpn "$1"
;;
stop)
screen -S vpn -X quit
;;
*)
curl ifconfig.co
;;
esac
and then you can add this as an alias:
alias vpn='bash /etc/openvpn/ovpn_tcp/go'
Usage:
# Start connection
vpn start
# Stop connection
vpn stop
# get status
vpn
As an alternative to an alias, you can put the script in your ~/bin, make it executable and add that directory to your $PATH.