This repository was archived by the owner on Mar 30, 2020. It is now read-only.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathssh-test
More file actions
Latest commit
executable file
·77 lines (59 loc) · 1.43 KB
/
Copy pathssh-test
File metadata and controls
executable file
·77 lines (59 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
#
# Functions
#
functionusage_and_exit {
cat <<EOF >&2
Usage: $0 <host-file>
Show whether it is possible to ssh into hosts listed in <host-file>.
Hostnames in <host-file> are separated by newlines and have the format:
[user@]hostname[:port]
Sample <host-file>:
example.vm.host.tld
me@remote.host.tld
root@bad.host.tld
deploy@production.live.example:2222
deploy@staging.live.example:2224
EOF
exit 1
}
#
# Command line options and arguments parsing
#
whilegetopts :h opt;do
case$optin
h) usage_and_exit
;;
'?') echo"$0 Invalid option -$OPTARG">&2
usage_and_exit
;;
esac
done
shift$((OPTIND -1))# remove options, leave arguments
if [ $#-ne 1 ];then
usage_and_exit
fi
#
# MAIN
#
# Calculate the longest hostname, to align columns if we can.
longest_hostname=0
forlinein$(cat "$1");do
length=${#line}
[ $length-gt$longest_hostname ] && longest_hostname=$length
done
RED='\033[1;31m'
NC='\033[0m'# No Color
forlinein$(cat "$1");do
host=${line%:*}
port=${line#*:}
if [ !-z"${port##*[!0-9]*}" ];then
portarg="-p $port"
fi
printf"%${longest_hostname}s ... "$line
if ssh -q -o BatchMode=yes -o ConnectTimeout=3 $portarg$hostexit2>/dev/null;then
echo"OK"
else
printf"${RED}FAIL${NC}\n"
fi
done