Skip to content

Instantly share code, notes, and snippets.

@ephemeralsnow
Last active August 29, 2015 14:24
Show Gist options
  • Save ephemeralsnow/225b89869a9ece984daf to your computer and use it in GitHub Desktop.
Save ephemeralsnow/225b89869a9ece984daf to your computer and use it in GitHub Desktop.
aws ec2 describe-instances から jq で /etc/hosts 作成
aws ec2 describe-instances --region ap-northeast-1 | jq -r '.Reservations[].Instances[] | select(.State.Name == "running") | .PrivateIpAddress as $private_ip | select($private_ip != null) | select(.Tags != null) | .Tags[] | select(.Key == "hostname") | select(. != null) | .Value as $host | select($host != null) | "\($private_ip)\t\t\($host)"' | sort -k2 | expand -t 8
sed '/^# ADDED BY THE PROGRAM$/,$d' | sed -e :a -e '/^\n*$/{$d;N;};/\n$/ba'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment