Skip to content

Instantly share code, notes, and snippets.

@rummelonp
Last active April 23, 2020 11:23
Show Gist options
  • Save rummelonp/37d927df399e0000180ff7a264efd3b0 to your computer and use it in GitHub Desktop.
Save rummelonp/37d927df399e0000180ff7a264efd3b0 to your computer and use it in GitHub Desktop.
EC2 の踏み台の .ssh/config 更新するクン
#!/usr/bin/env bash
aws --region=ap-northeast-1 ec2 describe-instances \
--query 'Reservations[*].Instances[*].{Name:Tags[?Key==`Name`]|[0].Value,Instance:InstanceId,Ip:PrivateIpAddress}' \
| jq '.[] | .[]' \
| jq --raw-output --slurp 'sort_by(.Name) | .[] | select(.Ip != null) | "Host " + .Name + "-" + .Instance, " HostName " + .Ip, ""' \
> /home/ec2-user/.ssh/config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment