Add run-on-all-nodes

This commit is contained in:
kayos@tcp.direct 2022-10-18 23:09:59 -07:00
commit 6f8dada9e0
Signed by: kayos
GPG Key ID: 4B841471B4BEE979
2 changed files with 35 additions and 0 deletions

16
lib.sh Normal file

@ -0,0 +1,16 @@
#!/usr/bin/env bash
get-targets() {
cat /etc/hosts | awk '{print $NF}' | grep -v localhost | grep -v "$(uname -n | awk -F '.' '{print $1}')" | /bin/grep "[a-z]"
}
export _ignore=("tcp.ac")
ignore() {
for iggie in "${_ignore[@]}"; do
echo "$iggie"
if [[ "$*" =~ $iggie ]]; then
true
fi
done
false
}

19
run-on-all-nodes.sh Executable file

@ -0,0 +1,19 @@
#!/usr/bin/env bash
source lib.sh
echo "preparing to run $* on all nodes"
_self="$(uname -n)"
set +e
echo "running on self"
ssh -n "$_self" "$@"
set -e
get-targets | while read -r line; do
if ! ignore "$line"; then
echo "running on $line"
ssh -n "$line" "$@" &
fi
done