Bash – Start a VPN session using a Terminal script

bashmac-osxscriptingterminalvpn

I use an OSX Terminal session to start a VPN connection. The command that I execute at the prompt is:

/etc/netlock/cvc -c ::

This works as expected.

I would like to save this to a script file that I can simply double-click to start.

I created a file, 'vpn.command', added the command (list above), save it, and given execute permission:

chmod +x vpn.command

When I double-click the file, Terminal opens a BASH shell, executes the command, then exits. Upon closer inspection, the command is now '/etc/netlock/cvc -c ::; exit;'

Why is the extra '; exit;' appended to my command?

BTW, is there a way to execute another command, /etc/netlock/cvc -d, when the Terminal session is being closed so I can close the VPN automatically?

Best Answer

I altered my command file to resemble the following:

#! /bin/bash

echo 'connecting...'
/etc/netlock/cvc -c connection:account:password

read -p "Press a key to disconnect."

echo 'disconnecting...'
/etc/netlock/cvc -d