42 lines
836 B
Bash
Executable File
42 lines
836 B
Bash
Executable File
#!/bin/bash
|
|
|
|
if [ "$#" -ne 2 ]; then
|
|
echo "Usage: $0 <localfile> <remotefile>"
|
|
exit 1
|
|
fi
|
|
|
|
localfile="$1"
|
|
remotefile="$2"
|
|
remotetmp="/var/tmp/4server"
|
|
|
|
|
|
|
|
while read -r host; do
|
|
echo "Processing host: $host"
|
|
|
|
host_env_file="$host_vars_dir/$host"
|
|
|
|
if [ ! -f "$host_env_file" ]; then
|
|
echo "Warning: env file for host '$host' not found at $host_env_file. Skipping."
|
|
continue
|
|
fi
|
|
|
|
declare -A vars=()
|
|
while IFS='=' read -r key value; do
|
|
[[ -z "$key" || -z "$value" ]] && continue
|
|
vars["$key"]="$value"
|
|
done < "$host_env_file"
|
|
|
|
content=$(cat "$localfile")
|
|
|
|
for key in "${!vars[@]}"; do
|
|
content=$(echo "$content" | sed "s|{$key}|${vars[$key]}|g")
|
|
done
|
|
|
|
echo "Copying to $host:$remotefile"
|
|
echo "$content" | ssh "$host" "cat > $remotetmp"
|
|
rex doas mv $remotetmp $remotefile
|
|
|
|
done < "$hosts_file"
|
|
|