From ab218353e3d1533a81cc987860c47956ece5c86f Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Thu, 26 Aug 2021 21:10:04 -0400 Subject: ssh-check --- ssh-check | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100755 ssh-check diff --git a/ssh-check b/ssh-check new file mode 100755 index 0000000..b6bfbd3 --- /dev/null +++ b/ssh-check @@ -0,0 +1,74 @@ +#!/bin/bash + +CFG_FILE=$HOME/.config/ssh-check.list +CFG_FILE_MAX=$((2**31-1)) + +read SSH_OPTIONS </dev/null 2>&1 +} + +c () +{ + local h hosts + read -r -N "$CFG_FILE_MAX" hosts < "$CFG_FILE" + if [ $# = 0 ]; then + set -- -4 + fi + while true; do + { + for h in $hosts + do + ( if p=$(quietly ssh $SSH_OPTIONS -n "$h" -- true) + then + echo "Succeeded: $h" + else + echo "Failed: $h" + fi ) & + done + wait + } | column -t -s'$' + tty -s && break + sleep 5 + done +} + +edit_config() +{ + set -e + f=$(tempfile) + if [ -e "$CFG_FILE" ] + then + cp "$CFG_FILE" "$f" + fi + touch -r "$f" "$f".timestamp + $EDITOR "$f" + [ -e "$f" -a "$f" -nt "$f".timestamp ] + mv "$f" "$CFG_FILE" + set +e + rm "$f".timestamp +} + +while [ $# -gt 0 ] +do + case "$1" in + --edit) edit_config; exit ;; + --) shift; break;; + *) exit 1 ;; + esac + shift +done + +if [ -t 0 ] && ! [ -e "$CFG_FILE" ] +then + edit_config +fi + +c "$@" -- cgit v1.2.3