Created
April 21, 2025 15:36
-
-
Save huynhbaoan/62145ca1d71ef131c133c49c4eeacb48 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Usage: ./run.sh <ips.csv> | |
set -euo pipefail | |
IP_CSV="$1" | |
OUT_LOG="combined-output.log" | |
# 1) Clear the single output file | |
: > "$OUT_LOG" | |
# 2) Process each line (skip header) | |
tail -n +2 "$IP_CSV" | while IFS=, read -r ip profile; do | |
# 3) Validate profile | |
if [[ -z "$profile" ]] || ! aws configure get aws_access_key_id --profile "$profile" &>/dev/null; then | |
# log invalid profile | |
printf '%s,Invalid profile\n' "$ip" >> "$OUT_LOG" | |
# extra message to stderr | |
echo "⛔ Invalid AWS profile for IP ${ip}: '${profile}'" >&2 | |
continue | |
fi | |
# 4) Run the lookup under that profile | |
export AWS_PROFILE="$profile" | |
if ! output=$(./runscript.sh "$ip"); then | |
# if runscript.sh failed, log a generic Error | |
printf '%s,Error\n' "$ip" >> "$OUT_LOG" | |
echo "⚠️ runscript.sh failed for IP $ip" >&2 | |
else | |
# runscript.sh is expected to emit "IP,Name" | |
printf '%s\n' "$output" >> "$OUT_LOG" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment