aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2016-08-20 02:25:21 +1200
committerTom Ryder <tom@sanctum.geek.nz>2016-08-20 02:25:21 +1200
commit2200d95ff52279f895e8f2a838d7cfa78b97742b (patch)
tree451a80979cc6a334e70331750da4c1741ce523e9 /bin
parentKeep SSH_TTY updated in tmux panes (diff)
downloaddotfiles-2200d95ff52279f895e8f2a838d7cfa78b97742b.tar.gz
dotfiles-2200d95ff52279f895e8f2a838d7cfa78b97742b.zip
Add sshi(1)
Diffstat (limited to 'bin')
-rwxr-xr-xbin/sshi28
1 files changed, 28 insertions, 0 deletions
diff --git a/bin/sshi b/bin/sshi
new file mode 100755
index 00000000..2f11a61d
--- /dev/null
+++ b/bin/sshi
@@ -0,0 +1,28 @@
+#!/bin/sh
+# Print some human-readable information from SSH_CONNECTION
+
+# Check we have an SSH_CONNECTION variable
+if [ -z "$SSH_CONNECTION" ] ; then
+ printf >&2 'sshi: SSH_CONNECTION appears empty\n'
+ exit 2
+fi
+
+# Print the two variables into a subshell so we can chop them up with read
+printf '%s\n' "$SSH_CONNECTION" "${SSH_TTY:-unknown}" | (
+
+ # Read connection details from first line
+ read -r ci cp si sp
+
+ # Read TTY from second line
+ read -r tty
+
+ # Try to resolve the client and server IPs
+ ch=$(dig -x "$ci" +short 2>/dev/null | sed 1q)
+ sh=$(dig -x "$si" +short 2>/dev/null | sed 1q)
+
+ # Print the results in a human-readable format
+ printf "%s:%u -> %s:%u (%s)\n" \
+ "${ch:-"$ci"}" "$cp" \
+ "${sh:-"$si"}" "$sp" \
+ "$tty"
+)