#!/bin/bash ssh_keyfile='/export/home/cloudian/cloudian-installation-key' script='stage1-gather-node-manifest.sh' # Ensure environment variables are set if [[ -z "$ssh_keyfile" || -z "$script" ]]; then echo "Error: Please set 'ssh_keyfile' and 'script' environment variables." exit 1 fi # Extract hostnames/IPs from /etc/hosts, skipping comments and localhost HOSTS=$(grep -v '^#' /etc/hosts | grep -v 'localhost' | awk '{print $2}') for HOST in $HOSTS; do echo "--- Executing on: $HOST ---" # Run the local script on the remote host using bash -s # -i: Uses the specified ssh_keyfile # -o StrictHostKeyChecking=no: Prevents the script from hanging on new host prompts ssh -i "$ssh_keyfile" -o StrictHostKeyChecking=no "$HOST" "bash -s" < "$script" # The loop naturally waits for the SSH command to finish before the next iteration echo "--- Finished: $HOST ---" done