Results 1 to 7 of 7

Thread: Help me write a script that will automate my VPN connection

  1. #1
    Join Date
    Oct 2005
    Location
    Shanghai
    Beans
    1,181
    Distro
    Xubuntu 12.04 Precise Pangolin

    Help me write a script that will automate my VPN connection

    I would like to have a script on my desktop ,clicking on it will connect me to a VPN server. At the moment I need to open a terminal
    cd to /etc/openvpn and then run this command:sudo openvpn --config 15\ -\ ibVPN\ USW.ovpn
    I then need to input my sudo password and my VPN credentials. I don't mind doing it, but my wife thinks it's 'complicated'. For some reason Network Manger can't connect to the VPN , only command line works, so a script is needed
    Any help would be appreciated

  2. #2
    Join Date
    Oct 2005
    Location
    Shanghai
    Beans
    1,181
    Distro
    Xubuntu 12.04 Precise Pangolin

    Re: Help me write a script that will automate my VPN connection

    this is what i've got so far :
    Code:
    #!/bin/bash
    cd /etc/openvpn
    sudo openvpn --config 12\ -\ itVPN\ USW.ovpn --auth-user-pass credentials
    When I run it I can see it going through the authentication process in the terminal but then the terminal just shuts off. I know it didn't connect cause I can't find an openvpn process running.
    I'm also not sure how my credentials file should look like- I tried like this:
    Code:
    Xauth username ${myusername}
    Xauth password ${mypassword}
    as well as :
    Code:
    myusername
    mypassword
    With the same results. Am I correct that I should locate the credentials file in /etc/openvpn?

  3. #3
    Join Date
    Feb 2011
    Location
    new york state
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Help me write a script that will automate my VPN connection

    you are using gnome/unity or kde ?
    Power tends to corrupt, and absolute power corrupts absolutely. Great men are almost always bad men, even when they exercise influence and not authority

  4. #4
    Join Date
    Feb 2011
    Location
    new york state
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Help me write a script that will automate my VPN connection

    Code:
    #!/bin/bash 
    
    
    gnome-terminal --working-directory /etc/openvpn -e 'bash -lc "cd /etc/openvpn ;sudo openvpn --config 12\ -\ itVPN\ USW.ovpn --auth-user-pass credentials ;bash"'


    that should work for gnome
    Last edited by josephmills; September 20th, 2011 at 03:47 PM.
    Power tends to corrupt, and absolute power corrupts absolutely. Great men are almost always bad men, even when they exercise influence and not authority

  5. #5
    Join Date
    Feb 2011
    Location
    new york state
    Beans
    Hidden!
    Distro
    Ubuntu Development Release

    Re: Help me write a script that will automate my VPN connection

    Well did it work ????
    Power tends to corrupt, and absolute power corrupts absolutely. Great men are almost always bad men, even when they exercise influence and not authority

  6. #6
    Join Date
    Oct 2005
    Location
    Shanghai
    Beans
    1,181
    Distro
    Xubuntu 12.04 Precise Pangolin

    Re: Help me write a script that will automate my VPN connection

    Well did it work ????
    Sorry for the late reply,
    I've modified the script according to your suggestion and indeed the terminal does not quit.It is trying to connect, but now I'm getting this:
    Code:
     AUTH: Received AUTH_FAILED control message
    which shows me that the authentication is not working. I can see several options:
    1. the credentials file is in the wrong format
    2. the credentials file is in the wrong directory (it's now in etc/openvpn)
    3. something else

    in the man page for openvpn it says :
    Note: OpenVPN will only read passwords from a file if it has been built with the --enable-password-save configure option
    not sure where to go from here....

  7. #7
    Join Date
    Oct 2005
    Location
    Shanghai
    Beans
    1,181
    Distro
    Xubuntu 12.04 Precise Pangolin

    Re: Help me write a script that will automate my VPN connection

    got it,
    just needed to specify the location of the credentials file, that's all
    so final script:
    Code:
    #!/bin/bash 
    
    
    gnome-terminal --working-directory /etc/openvpn -e 'bash -lc "cd /etc/openvpn ;sudo openvpn --config 12\ -\ itVPN\ USW.ovpn --auth-user-pass /etc/openvpn/credentials ;bash"'

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •