diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-20 02:25:21 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2016-08-20 02:25:21 +1200 |
commit | 2200d95ff52279f895e8f2a838d7cfa78b97742b (patch) | |
tree | 451a80979cc6a334e70331750da4c1741ce523e9 | |
parent | Keep SSH_TTY updated in tmux panes (diff) | |
download | dotfiles-2200d95ff52279f895e8f2a838d7cfa78b97742b.tar.gz dotfiles-2200d95ff52279f895e8f2a838d7cfa78b97742b.zip |
Add sshi(1)
-rw-r--r-- | README.markdown | 1 | ||||
-rwxr-xr-x | bin/sshi | 28 | ||||
-rw-r--r-- | man/man1/sshi.1 | 15 |
3 files changed, 44 insertions, 0 deletions
diff --git a/README.markdown b/README.markdown index d6ace0d3..3bf1e604 100644 --- a/README.markdown +++ b/README.markdown @@ -426,6 +426,7 @@ Installed by the `install-bin` target: * `rmrej(1)` deletes rejected hunks from a failed `patch(1)` run. * `shb(1)` attempts to build shebang lines for scripts from `$PATH`. * `spr(1)` posts its input to the sprunge.us pastebin. +* `sshi(1)` prints human-readable SSH connection details. * `stex(1)` strips extensions from filenames. * `sue(8)` execs `sudoedit(8)` as the owner of all the file arguments given, perhaps in cases where you may not necessarily have `root` `sudo(8)` 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" +) diff --git a/man/man1/sshi.1 b/man/man1/sshi.1 new file mode 100644 index 00000000..8f9ee41d --- /dev/null +++ b/man/man1/sshi.1 @@ -0,0 +1,15 @@ +.TH SSHI 1 "August 2016" "Manual page for sshi" +.SH NAME +.B sshi +\- show human-readable details of the current SSH connection +.SH SYNOPSIS +.B sshi +.SH DESCRIPTION +.B sshi +interprets the contents of the SSH_CONNECTION variable available in the +environment of SSH client sessions and presents it in a slightly more +human-readable format, including an attempt to resolve the IP addresses. +.SH SEE ALSO +ssh(1) +.SH AUTHOR +Tom Ryder <tom@sanctum.geek.nz> |