4848028 [rkeene@sledge /home/rkeene/tmp]$ cat -n zone-vnc-proxy.sh
 1 #! /bin/bash
 2 
 3 host="$1"
 4 port="$2"
 5 zone="$3"
 6 
 7 localZone="$(cat /var/run/cluster-control/facts/federation/zone-id 2>/dev/null)"
 8 if [ -z "${localZone}" -o -z "${zone}" -o "${zone}" = "${localZone}" ]; then
 9     echo "${host}:${port}"
10 
11     exit 0
12 fi
13 
14 hashID="${host}:${port}:${zone}"
15 hash="$(echo "${hashID}" | openssl dgst -sha1 | sed 's@^.*= *@@')"
16 forwardIP="$(printf '127.%i.%i.254\n' $(echo "${hash}" | sed 's@^.*\(..\)\(..\)$@0x\1 0x\2@'))"
17 forwardPort="$(echo $[$(echo "${hash}" | sed 's@^.*\(....\)....$@0x\1@') % 1024 + 31744])"
18 
19 (
20     sshControlSocket="${TMPDIR:-/tmp}/aurae-zones-vnc-proxy-ssh-${hash}"
21     sshArgs=(
22         -o ServerAliveInterval=120
23         -o StrictHostKeyChecking=no
24         -o BatchMode=yes
25         -o PasswordAuthentication=no
26         -o KbdInteractiveAuthentication=no
27         -o ControlMaster=yes
28         -S "${sshControlSocket}" 
29         -a -T -f
30     )
31 
32     sshPid="$(ssh -S "${sshControlSocket}" -O check /dev/null 2>&1 | grep 'pid=' | sed 's@.*pid=@@;s@).*$@@')"
33     if [ -z "${sshPid}" ]; then
34         peer="aurae-dashboard-zone-${zone}"
35 
36         timeout 120 ssh "${sshArgs[@]}" -L"${forwardIP}:${forwardPort}:${host}:${port}" "${peer}" 'sleep 7200'
37         sshPid="$(ssh -S "${sshControlSocket}" -O check /dev/null 2>&1 | grep 'pid=' | sed 's@.*pid=@@;s@).*$@@')"
38     fi
39 
40     if [ -z "${sshPid}" ]; then
41         echo "SSH session failed" >&2
42 
43         exit 1
44     fi
45 ) </dev/null >/dev/null || exit 1
46 
47 echo "${forwardIP}:${forwardPort}"
48 
49 exit 0
4848029 [rkeene@sledge /home/rkeene/tmp]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2016-12-19 12:19:52