Last active
August 29, 2015 14:06
-
-
Save sechiro/d34d62f77554c7b6698b to your computer and use it in GitHub Desktop.
ec2sshぽい何か。VPC内でPrivateDnsNameで接続する用。
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
aws ec2 describe-instances | jq -r '.Reservations[].Instances[]| (.Tags[] | select(.Key=="Name").Value) + " " + .PrivateDnsName' > /tmp/instance_list | |
OLDIFS=$IFS | |
while read line | |
do | |
IFS=" " | |
set -- $line | |
echo "Host $1 | |
Hostname $2" | |
done < /tmp/instance_list > /tmp/ssh_config | |
IFS=$OLDIFS | |
# ~/.ssh/config の最後に「##### EC2SSH.sh #####」をつけること | |
sed -i '/^##### EC2SSH.sh #####/q' ~/.ssh/config | |
cat /tmp/ssh_config >> ~/.ssh/config |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment