diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-04-05 20:06:39 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-04-05 20:46:47 +1200 |
commit | c8ab406749124d2e762ad5cf53963070113afd0f (patch) | |
tree | 54c9721a06957ebe7098a211eea803b0230c0f5d /bin/sshi.sh | |
parent | Handle POSIX correctness in ~/.bash_profile (diff) | |
download | dotfiles-c8ab406749124d2e762ad5cf53963070113afd0f.tar.gz dotfiles-c8ab406749124d2e762ad5cf53963070113afd0f.zip |
Apply runtime shebanging to POSIX shell
Diffstat (limited to 'bin/sshi.sh')
-rw-r--r-- | bin/sshi.sh | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/bin/sshi.sh b/bin/sshi.sh new file mode 100644 index 00000000..0d1591f1 --- /dev/null +++ b/bin/sshi.sh @@ -0,0 +1,27 @@ +# 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 1 +fi + +# Print the two variables into a compound command so we can `read` them +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 's/\.$//;1q') + sh=$(dig -x "$si" +short 2>/dev/null | sed 's/\.$//;1q') + + # Print the results in a human-readable format + printf "%s:%u -> %s:%u (%s)\n" \ + "${ch:-"$ci"}" "$cp" \ + "${sh:-"$si"}" "$sp" \ + "$tty" +} |