Skip to content

Instantly share code, notes, and snippets.

@sjmcgrath
Created September 18, 2017 21:50
Show Gist options
  • Save sjmcgrath/4da23bde08e8477c5655e02bf72d3510 to your computer and use it in GitHub Desktop.
Save sjmcgrath/4da23bde08e8477c5655e02bf72d3510 to your computer and use it in GitHub Desktop.
Gets a list of Digital Ocean droplets and their IP addresses
#!/bin/bash
set -o errexit
# DO_KEY_CONFIG_FILE should contain one line similar to the following with a Digital Ocean read key
# header = "Authorization: Bearer 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
DO_KEY_CONFIG_FILE=${DO_KEY_CONFIG_FILE:?Must specify DO_KEY_CONFIG_FILE}
BASE="https://api.digitalocean.com"
ENDPOINT="/v2/droplets"
URL="${BASE}${ENDPOINT}"
curl --silent -X GET -K "${DO_KEY_CONFIG_FILE}" -- "${URL}" \
| jq -r '.droplets[] | [.name, .networks.v4[0].ip_address] | join(" ")'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment