-
Notifications
You must be signed in to change notification settings - Fork 6
/
sssh
executable file
·78 lines (71 loc) · 2.01 KB
/
sssh
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
78
#!/bin/zsh
# multi-host ssh controller
clear
autoload colors; colors
error() { echo "${fg[red]}$@${reset_color}" >&2 }
warn() { echo "${fg[yellow]}$@${reset_color}" >&2 }
good() { echo "${fg[green]}$@${reset_color}" >&2 }
banner=`echo \
'CiBfICAgICBfICAgICAgIF8gICAgICAgICAgICAgICAgXwp8IHxfXyAoXykgX18g\
X3wgfF9fICBfIF9fICAgX19ffCB8Xwp8ICdfIFx8IHwvIF9gIHwgJ18gXHwgJ18gX\
CAvIF8gXCBfX3wKfCB8IHwgfCB8IChffCB8IHwgfCB8IHwgfCB8ICBfXy8gfF8KfF\
98IHxffF98XF9fLCB8X3wgfF98X3wgfF98XF9fX3xcX198CiAgICAgICAgIHxfX18\
vCSAgICAgIAkgIHNoZWxsanVtcAoK' \
| base64 --decode`
echo "${fg[green]}$banner${reset_color}"
echo
if [ -f ~/.kerchow-hosts ]; then
hosts=($(cat ~/.kerchow-hosts))
else
error "config file missing, create ~/.kerchow-hosts with one hostname per line."
exit 1
fi
process_host() {
local host="$1"
local usrcommand="$2"
resolve_address=$(host "${host}" | awk '/has address/ { print $4 }')
if [ -z "${resolve_address}" ]
then
if [ "${host}" != "pihole.nameserv" ]
then
warn "${host} | failed to resolve"
return
fi
fi
good "${host} | ${fg[yellow]}${resolve_address}${reset_color}"
ssh -q -t -o ConnectTimeout=2 "${host}" "${usrcommand}"
}
hosts=(all parallel "${hosts[@]}")
select host in "${hosts[@]}"; do
if [ -n "${host}" ]; then
break
fi
done
if [ "${host}" = "all" ] || [ "${host}" = "parallel" ]
then
if [ -z "${1}" ]
then
vared -p 'command to run: ' -c usrcommand
else
usrcommand="${1}"
fi
echo "${usrcommand}" | lolcat
for host in "${hosts[@]}"; do
if [ "${host}" = "all" ] || [ "${host}" = "parallel" ]
then
continue
fi
if [ "${select_host}" = "parallel" ]; then
(
process_host "${host}" "${usrcommand}"
) &
else
process_host "${host}" "${usrcommand}"
fi
done
if [ "${select_host}" = "parallel" ]; then
wait
fi
else
ssh -q -t -o ConnectTimeout=2 "${host}" "${1}"
fi