Linux Training

Linux training for private, public & voluntary sector.

0793 572 8612

City LinUX sample scripts - vn-connect


#!/bin/bash
# $Id: vn-connect,v 1.33 2015/01/23 10:36:04 fulford Exp $
# $Source: /src/merlin/usr/local/etc/RCS/vn-connect,v $
# $Revision: 1.33 $
# Author C W Fulford.
# Copyright 2014 (c) C W Fulford.
# Licensed for public use under the LGPL, .
# For assistance contact fulford@fulford.net 0709 229 5385
########################################################################
cmd=`basename $0`
syntax="$cmd [-c <filename>] [-d] [-v] <hostid>"
while [ $# -gt 0 ] ;do
	case $1 in 
		-c) conf=$2 ;shift 2;;
		-d) set -x;debug=:;shift;;
		-v) verbose=:;dump=dump;shift;;
		*) hostid=$1;shift;;
	esac
done
[ $hostid ] ||{
	echo "syntax: $syntax" >&2
	exit 1
}

conf=${conf:="/usr/local/etc/vn-connect.cf"}
[ -f $conf ] ||{ echo "$cmd: can't find $conf">&2 ;exit 1;}

grep -qe "^$hostid:$" $conf||{ echo "$cmd: $hostid not found in $conf" >&2 
	exit 1
}

eval `sed -ne "/^$hostid:$/,/^$/{
	/^[ 	][^#]*/p
}" $conf`
if=${if:-ppp0}

#if connection already exists terminate
netstat  -nr |grep $network|grep $if && {
	[ $verbose ] && echo "$cmd: connection to $hostid already exists.">&2
	exit 1
}


case $conn in
	vpn)sudo $vpn $dump ;sleep 3;$route ;;
esac

######################################################################
# This program is free software: you can redistribute it and or      #
# modify it under the terms of the Lesser GNU General Public License #
# as published by the Free Software Foundation, either version 3 of  #
# the License, or (at your option) any later version.                #
#                                                                    #
# This program is distributed in the hope that it will be useful,    #
# but WITHOUT ANY WARRANTY; without even the implied warranty of     #    
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      #
# GNU General Public License for more details.                       #
#                                                                    # 
# A copy of the Lesser GNU General Public License and the GNU        #
# General Public License is available at                             #
# <http://www.gnu.org/licenses/>.                                    #
######################################################################

The layout and associated style sheets for this page are taken from the World Wide Web Consortium and used here under the W3C software licence.