diff options
author | Andrew Cady <d@jerkface.net> | 2024-02-10 23:43:13 -0500 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2024-02-10 23:43:13 -0500 |
commit | eb59877b0b9db7bdf0d0326d09d096ff77b9e282 (patch) | |
tree | b83b010d91b8f93e953cdaa0879187eff2c143c3 | |
parent | 26607143c41319673cdbad366b7e5388ce8d807c (diff) |
improvements?
-rwxr-xr-x | ssh-check | 40 |
1 files changed, 24 insertions, 16 deletions
@@ -3,10 +3,7 @@ | |||
3 | CFG_FILE=$HOME/.config/ssh-check.list | 3 | CFG_FILE=$HOME/.config/ssh-check.list |
4 | TIMEOUT=5 # seconds | 4 | TIMEOUT=5 # seconds |
5 | 5 | ||
6 | 6 | read -d '' SSH_OPTIONS <<END | |
7 | read_all='read -N2147483647' | ||
8 | |||
9 | $read_all SSH_OPTIONS <<END | ||
10 | -o ConnectTimeout=$TIMEOUT | 7 | -o ConnectTimeout=$TIMEOUT |
11 | -o ControlPath=none | 8 | -o ControlPath=none |
12 | -o PasswordAuthentication=no | 9 | -o PasswordAuthentication=no |
@@ -33,28 +30,39 @@ match() | |||
33 | 30 | ||
34 | main() | 31 | main() |
35 | { | 32 | { |
36 | local h hosts | 33 | local h |
37 | $read_all -r hosts < "$CFG_FILE" | 34 | declare -a hosts=() |
38 | host_field_width=1 | 35 | mapfile hosts < "$CFG_FILE" |
39 | for h in $hosts | 36 | MIN_HOST_FIELD_WIDTH=10 |
37 | host_field_width=$MIN_HOST_FIELD_WIDTH | ||
38 | for h in ${hosts[@]} | ||
40 | do | 39 | do |
41 | if [ ${#h} -gt $host_field_width ] | 40 | if [ ${#h} -gt $host_field_width ] |
42 | then | 41 | then |
43 | host_field_width=${#h} | 42 | host_field_width=${#h} |
44 | fi | 43 | fi |
45 | done | 44 | done |
46 | while true; do | 45 | while true |
46 | do | ||
47 | { | 47 | { |
48 | for h in $hosts | 48 | for h in ${hosts[@]} |
49 | do | 49 | do |
50 | [ $# = 0 ] || match "$h" "$@" || continue | 50 | [ $# = 0 ] || match "$h" "$@" || continue |
51 | 51 | ||
52 | ( if uptime=$(ssh $SSH_OPTIONS -n "$h" -- ${REMOTE_COMMAND:-uptime} 2>/dev/null) | 52 | ( |
53 | then | 53 | #.........."1234567890123456" |
54 | printf "%-15s %-${host_field_width}s %s\n" "Succeeded:" "$h" "${uptime# }" | 54 | successpat=" Success: %-${host_field_width}s %s\n" |
55 | else | 55 | failurepat="*FAILURE: %-${host_field_width}s\n" |
56 | printf "%-15s %-${host_field_width}s\n" "Failed:" "$h" | 56 | if command_stdout=$(ssh -n $SSH_OPTIONS \ |
57 | fi ) & | 57 | "$h" -- \ |
58 | ${REMOTE_COMMAND:-uptime} \ | ||
59 | 2>/dev/null) | ||
60 | then | ||
61 | printf "$successpat" "$h" "${command_stdout# }" | ||
62 | else | ||
63 | printf "$failurepat" "$h" | ||
64 | fi | ||
65 | ) & | ||
58 | done | 66 | done |
59 | wait | 67 | wait |
60 | } | column -t -s'$' | 68 | } | column -t -s'$' |