-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssh_proxy.sh
63 lines (50 loc) · 1.25 KB
/
ssh_proxy.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
55
56
57
58
59
60
61
62
#!/bin/bash
## Proxy service configuration script for OSX
## tested on MacOS Sierra
##
ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source ${ROOT_DIR}/config.sh
SSH_CMD="ssh ${SSH_OPTS} ${PORT} -p ${SSH_PORT} ${SSH_HOST}"
function report {
MSG=$1
if [ -n "${VERBOSE}" ]; then
echo $MSG
fi
}
function enableProxy {
${SSH_CMD} ${SSH_DEBUG_OPTS} 2> ${LOG_FILE}
showStatus
if [ $? != 0 ]; then
echo Please check ${LOG_FILE} for more detailed information
fi
}
function disableProxy {
ps -ax | grep "${SSH_CMD}" | grep -v grep | awk '{print $1}'| xargs kill
showStatus
}
function showStatus {
ps -ax | grep "ssh " | grep -v grep
ps -ax | grep "${SSH_CMD}" | grep -v grep > /dev/null
if [ $? -eq 0 ]; then
echo SSH SOCKS Proxy: ON
return 0
else
echo SSH SOCKS Proxy: OFF
return 1
fi
}
case "$1" in
on) report "Enabling Proxy"
enableProxy
;;
off) report "Disabling Proxy"
disableProxy
;;
status) echo status
showStatus
;;
*) echo Options:
echo " on enable proxy"
echo " off disable proxy"
echo " status see proxy status"
esac