From b215624ad246011ffc268da0aa74d5ee0aa19be9 Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Sun, 17 Nov 2024 10:38:39 -0500 Subject: [PATCH] add batch command script --- for | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100755 for diff --git a/for b/for new file mode 100755 index 0000000..b2a1e9b --- /dev/null +++ b/for @@ -0,0 +1,26 @@ +#!/bin/bash + +set -o errexit -o nounset -o pipefail + +[[ $# -eq 2 ]] || exit 1 + +input= +read -p "Run command '$2' across $1 servers? " input +if [[ $input != yes ]]; then + exit 1 +fi +echo + +user=root + +. hosts.sh + +declare -n hosts=hosts_$1 +for host in ${hosts[@]}; do + echo $host + echo + + ssh $user@$host "$2" + + echo +done