Skip to main content
1 of 6
pLumo
  • 23.2k
  • 2
  • 43
  • 70

Use full path in set command, run screen in detached mode and use a case ... esac construct 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'

Alternatively, you can put the script in your ~/bin, make it executable and add that directory to your $PATH.

pLumo
  • 23.2k
  • 2
  • 43
  • 70