summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2021-08-26 21:10:04 -0400
committerAndrew Cady <d@jerkface.net>2021-08-26 21:10:04 -0400
commitab218353e3d1533a81cc987860c47956ece5c86f (patch)
tree80c13061430f4a6bbb3474bdc5eebc4fd9d2ae2e
ssh-check
-rwxr-xr-xssh-check74
1 files changed, 74 insertions, 0 deletions
diff --git a/ssh-check b/ssh-check
new file mode 100755
index 0000000..b6bfbd3
--- /dev/null
+++ b/ssh-check
@@ -0,0 +1,74 @@
1#!/bin/bash
2
3CFG_FILE=$HOME/.config/ssh-check.list
4CFG_FILE_MAX=$((2**31-1))
5
6read SSH_OPTIONS <<END
7-o ConnectTimeout=3
8-o ControlPath=none
9-o PasswordAuthentication=no
10-o StrictHostKeyChecking=yes
11END
12
13quietly()
14{
15 "$@" </dev/null >/dev/null 2>&1
16}
17
18c ()
19{
20 local h hosts
21 read -r -N "$CFG_FILE_MAX" hosts < "$CFG_FILE"
22 if [ $# = 0 ]; then
23 set -- -4
24 fi
25 while true; do
26 {
27 for h in $hosts
28 do
29 ( if p=$(quietly ssh $SSH_OPTIONS -n "$h" -- true)
30 then
31 echo "Succeeded: $h"
32 else
33 echo "Failed: $h"
34 fi ) &
35 done
36 wait
37 } | column -t -s'$'
38 tty -s && break
39 sleep 5
40 done
41}
42
43edit_config()
44{
45 set -e
46 f=$(tempfile)
47 if [ -e "$CFG_FILE" ]
48 then
49 cp "$CFG_FILE" "$f"
50 fi
51 touch -r "$f" "$f".timestamp
52 $EDITOR "$f"
53 [ -e "$f" -a "$f" -nt "$f".timestamp ]
54 mv "$f" "$CFG_FILE"
55 set +e
56 rm "$f".timestamp
57}
58
59while [ $# -gt 0 ]
60do
61 case "$1" in
62 --edit) edit_config; exit ;;
63 --) shift; break;;
64 *) exit 1 ;;
65 esac
66 shift
67done
68
69if [ -t 0 ] && ! [ -e "$CFG_FILE" ]
70then
71 edit_config
72fi
73
74c "$@"