#!/bin/bash ssh_keyfile='/export/home/cloudian/cloudian-installation-key' # Set the path to the remote file you want to download remote_file='/root/manifest-*txt*' # Ensure variables are set if [[ -z "$ssh_keyfile" || -z "$remote_file" ]]; then echo "Error: Please set 'ssh_keyfile' and 'remote_file' 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 "--- Fetching from: $HOST ---" # Create a unique local directory for this host's file #target_dir="remotes/$HOST" target_dir="remotes/" mkdir -p "$target_dir" # Use SCP to pull the file from the remote host to the local directory # -i: Specifies the identity (private key) file # -o StrictHostKeyChecking=no: Skips manual fingerprint verification prompts scp -i "$ssh_keyfile" -o StrictHostKeyChecking=no "$HOST":"$remote_file" "$target_dir/" if [ $? -eq 0 ]; then echo "--- Success: File saved to $target_dir/ ---" else echo "--- Failed: Could not fetch from $HOST ---" fi done