Skip to content

Commit

Permalink
list-instances - merge JQ script to SH script
Browse files Browse the repository at this point in the history
  • Loading branch information
mludvig committed Sep 8, 2016
1 parent 3513047 commit 64ce001
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
21 changes: 0 additions & 21 deletions jq/list-instances.jq

This file was deleted.

26 changes: 22 additions & 4 deletions list-instances/list-instances
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,26 @@

set -e

export SCRIPTS_DIR=$(dirname $0)
test -z "${SCRIPTS_DIR}" && SCRIPTS_DIR=$(dirname $(which $0))
export JQ_DIR=${SCRIPTS_DIR}/../jq
aws ec2 describe-instances | jq -r '
# Right-pad string with spaces
def pad(width):
tostring | if width > length then . + (width - length) * " " else . end;
aws ec2 describe-instances | jq -f ${JQ_DIR}/list-instances.jq -r
# Display running instances Name and PrivateIpAddress
[
.Reservations[].Instances[]
| select(.State.Name == "running" and .Tags != null)
| {
"PrivateIpAddress": .PrivateIpAddress?,
"Name": .Tags[] | select(.Key == "Name") | .Value,
}
]
| sort_by(.Name)
| group_by(.Name)
| .[]
| {
"FmtName": .[0].Name | pad(30),
"FmtIpAddr": [ .[].PrivateIpAddress ] | join(" ")
}
| @text "\(.FmtName) \(.FmtIpAddr)"
'

0 comments on commit 64ce001

Please sign in to comment.