Last active
August 29, 2015 14:24
-
-
Save ephemeralsnow/225b89869a9ece984daf to your computer and use it in GitHub Desktop.
aws ec2 describe-instances から jq で /etc/hosts 作成
This file contains 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
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