1

I have subscribed to a VPN service and now I have a few .ovpn files, one for each server. What I'd like to do is creating a shell script in which I can select the file to be loaded, and launch that connection. This is my script:

#!/bin/bash

TITLE="Start a VPN Connection"
FOLDER=$HOME"/ovpn/"
CHOICE=$(zenity --file-selection --title="Select your desired VPN config" --filename="$FOLDER" --file-filter="*.ovpn")
VPNFILE=$(basename "$CHOICE")

clear
sudo openvpn --cd "$FOLDER" --config "'$VPNFILE'" --verb 1 --auth-user-pass "auth.txt" --auth-nocache

Now, the problem is that when I launch this script I can select an .ovpn file, but the script crashes because of this error:

Options error: In [CMD-LINE]:1: Error opening configuration file: 'Server-1.ovpn'

If I edit the last line in my script, using echo instead of sudo, I obtain a connection string. If I copy&paste that line and manually run the generated command, the connections starts and works good.

Is there something wrong in trying to open a openvpn connection from a shell script?

3

Drop the single quotes from "'$VPNFILE'" or they will be taken to be part of the filename of the configuration file.

  • Well you were right! They were left from previous try and errors... dropping those quotes solved my problem. Thanks! – ToX 82 Jun 13 '17 at 10:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.