-
Notifications
You must be signed in to change notification settings - Fork 6
/
foreach.sh
executable file
·58 lines (48 loc) · 1.07 KB
/
foreach.sh
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
#!/usr/bin/env bash
set -of pipefail
GRN='\033[0;32m'
BLD='\033[1m'
RST='\033[0m'
DOMAIN='status.im'
function fleets() {
grep -oP '^\[\K[^]]+' ansible/inventory/test
}
function hosts() {
awk "
/^\[${1}\]$/{
while (\$0 != \"\") {
getline
print(\$1)
continue
}
}
" ansible/inventory/test
}
function ssh_command() {
echo -e "${GRN}${BLD}${1}${RST}"
ssh -o StrictHostKeyChecking=accept-new "${1}.${DOMAIN}" "${2}"
}
function usage() {
echo "
Usage: $0 [FLEET] <COMMAND>
Examples:
$0 nimbus.sepolia 'systemctl start build-beacon-node-sepolia-stable'
echo linux-01.ih-eu-mda1.nimbus.sepolia | $0 'systemctl start build-beacon-node-sepolia-stable'
"
}
if [[ "${#}" -eq 0 ]]; then
usage
echo -e "Available fleets:\n"
fleets
exit
elif [[ "${#}" -eq 1 ]]; then
# Get hostnames from stdin.
while IFS=$'\n' read -r FLEET_HOST; do
ssh_command "${FLEET_HOST}" "${1}"
done
else
# Get hostnames using fleet name.
for FLEET_HOST in $(hosts "${1}"); do
ssh_command "${FLEET_HOST}" "${2}"
done
fi