-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen-vpn-disconnect.sh
executable file
·54 lines (44 loc) · 1.42 KB
/
open-vpn-disconnect.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
#
# open-vpn-disconnect.sh (ucivpndown.sh)
#
# From: http://www.socsci.uci.edu/~jstern/uci_vpn_ubuntu/ubuntu-openconnect-uci-instructions.html
#
#
# Where you want any output of status / errors to go
# (this should match same var in the open-vpn-connect.sh script)
# (required)
OC_LOG="/tmp/OC_LOG.txt"
OPENVPN_EXE='/usr/sbin/openvpn'
if [[ ! -f "${OPENVPN_EXE}" ]]; then
echo "ERROR: ${OPENVPN_EXE} does not exist on your system. Please install."
exit 1
fi
# ----------------------------------------------------------
# You should not have to change or edit anything below here
# ----------------------------------------------------------
# become root if not already
if [ $EUID != 0 ]; then
sudo "$0"
exit $?
fi
echo "`date`: Script ${0} starting." >> "${OC_LOG}" 2>&1
#
# Shut down openconnect process if one (or more) exists
#
# Find the pid(s) of any openconnect process(es)
pidofoc=`pidof openconnect`
# Use those pids to kill them
if [ "$pidofoc" != "" ]; then
echo "`date`: Stopping openconnect PID ${pidofoc}." >> "${OC_LOG}" 2>&1
kill -9 ${pidofoc} >> "${OC_LOG}" 2>&1
else
echo "`date`: No openconnect found. (That's okay.) Continuing." >> "${OC_LOG}" 2>&1
fi
# Close down the tun1 openvpn tunnel
${OPENVPN_EXE} --rmtun --dev tun1 &>> "${OC_LOG}"
# Finally, restore the /tmp/resolv.conf
if [[ -f /tmp/resolv.conf ]]; then
cp /tmp/resolv.conf /etc
fi
echo "`date`: ${0} script ending successfully." >> "${OC_LOG}" 2>&1