summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2021-08-30 13:02:33 -0400
committerAndrew Cady <d@jerkface.net>2021-08-30 13:02:33 -0400
commitea405c08a6f062eb58219a6a1a177feb470dd8ee (patch)
treec94dbcec48ede66b567544cef5db3a3aabe31bb9
parentab218353e3d1533a81cc987860c47956ece5c86f (diff)
improvements
-rwxr-xr-xssh-check39
1 files changed, 30 insertions, 9 deletions
diff --git a/ssh-check b/ssh-check
index b6bfbd3..c2f18d7 100755
--- a/ssh-check
+++ b/ssh-check
@@ -1,10 +1,13 @@
1#!/bin/bash 1#!/bin/bash
2 2
3CFG_FILE=$HOME/.config/ssh-check.list 3CFG_FILE=$HOME/.config/ssh-check.list
4CFG_FILE_MAX=$((2**31-1)) 4TIMEOUT=5 # seconds
5 5
6read SSH_OPTIONS <<END 6
7-o ConnectTimeout=3 7read_all='read -N2147483647'
8
9$read_all SSH_OPTIONS <<END
10-o ConnectTimeout=$TIMEOUT
8-o ControlPath=none 11-o ControlPath=none
9-o PasswordAuthentication=no 12-o PasswordAuthentication=no
10-o StrictHostKeyChecking=yes 13-o StrictHostKeyChecking=yes
@@ -18,19 +21,27 @@ quietly()
18c () 21c ()
19{ 22{
20 local h hosts 23 local h hosts
21 read -r -N "$CFG_FILE_MAX" hosts < "$CFG_FILE" 24 $read_all -r hosts < "$CFG_FILE"
22 if [ $# = 0 ]; then 25 if [ $# = 0 ]; then
23 set -- -4 26 set -- -4
24 fi 27 fi
28 host_field_width=1
29 for h in $hosts
30 do
31 if [ ${#h} -gt $host_field_width ]
32 then
33 host_field_width=${#h}
34 fi
35 done
25 while true; do 36 while true; do
26 { 37 {
27 for h in $hosts 38 for h in $hosts
28 do 39 do
29 ( if p=$(quietly ssh $SSH_OPTIONS -n "$h" -- true) 40 ( if uptime=$(ssh $SSH_OPTIONS -n "$h" -- uptime 2>/dev/null)
30 then 41 then
31 echo "Succeeded: $h" 42 printf "%-15s %-${host_field_width}s %s\n" "Succeeded:" "$h" "${uptime# }"
32 else 43 else
33 echo "Failed: $h" 44 printf "%-15s %-${host_field_width}s\n" "Failed:" "$h"
34 fi ) & 45 fi ) &
35 done 46 done
36 wait 47 wait
@@ -56,17 +67,27 @@ edit_config()
56 rm "$f".timestamp 67 rm "$f".timestamp
57} 68}
58 69
70unset run_anyway do_edit
59while [ $# -gt 0 ] 71while [ $# -gt 0 ]
60do 72do
61 case "$1" in 73 case "$1" in
62 --edit) edit_config; exit ;; 74 --edit) do_edit=y;;
75 --run) run_anyway=y;;
63 --) shift; break;; 76 --) shift; break;;
64 *) exit 1 ;; 77 *) exit 1 ;;
65 esac 78 esac
66 shift 79 shift
67done 80done
68 81
69if [ -t 0 ] && ! [ -e "$CFG_FILE" ] 82if [ "$do_edit" ]
83then
84 edit_config
85 r=$?
86 if ! [ "$run_anyway}" ]
87 then
88 exit $r
89 fi
90elif [ ! -e "$CFG_FILE" -a -t 0 ]
70then 91then
71 edit_config 92 edit_config
72fi 93fi