-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzssh
More file actions
executable file
·75 lines (71 loc) · 1.85 KB
/
zssh
File metadata and controls
executable file
·75 lines (71 loc) · 1.85 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
#
# A utility for logging into hosts in the local domain by looking up a
# substring of their hostname in the local multicast DNS i.e. using
# zeroconf. The lookup is performed by invoking zeroconf-ssh-host and
# taking the first match.
#
# conditional printf
function vftrace() {
if [[ -n "$VERBOSE" ]]; then
printf "$@"
fi
}
PLATFORM=`uname -a`
if [[ ! ${PLATFORM} =~ Darwin ]]; then
echo "Non-Darwin platforms unsupported!"
exit 1
fi
if [[ -z "$1" ]]; then
echo "Usage: $0 <hostname>"
exit 1
fi
VERBOSE=""
# First process and consume flags
while [[ "$#" -gt 1 ]]; do
if [[ "$1" = "-v" ]]; then
VERBOSE=true
VERBOSEFLAG="-v"
vftrace "verbose\n"
shift
elif [[ "$1" = "-h" ]]; then
USEHOSTNAME=true
vftrace "hostname mode\n"
shift
else
vftrace "\"$1\" unrecognized, ignored\n"
shift
fi
done
HOST="$1"
shift
# If the address is of the form user@host then split it at the @
# symbol to get the user and the host separately
if [[ $HOST =~ \@ ]]; then
# append the @ symbol again to make the construction of the entire
# address easy later
SSHUSER=`echo $HOST | awk -F "@" '{print $1}'`\@
# the hostname is unadorned
HOST=`echo $HOST | awk -F "@" '{print $2}'`
fi
vftrace "try zeroconf-ssh-host $HOST...\n"
ENTRY=`zeroconf-ssh-host ${VERBOSEFLAG} ${HOST} | grep .local`
if [[ -z "$ENTRY" ]]; then
echo "Host \"$HOST\" not found\n"
exit 1
else
vftrace "zeroconf returned:\n$ENTRY\n"
fi
HN=`echo $ENTRY | awk '{print $5}'`
IP=`echo $ENTRY | awk '{print $6}'`
vftrace "hostname $HN IP address $IP\n"
if [[ -n "$USEHOSTNAME" ]]; then
TARGET=$HN
else
TARGET=$IP
fi
if [[ -n ${TARGET} ]]; then
vftrace "Found $TARGET in local domain\n"
vftrace "Output of \"ssh ${SSHUSER}${TARGET} ${@}\" :\n"
ssh ${SSHUSER}${TARGET} $@
fi