Skip to content

Instantly share code, notes, and snippets.

@seven1m
Last active November 8, 2021 18:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seven1m/b876cfa610eba0df1ba7aa0837e937b8 to your computer and use it in GitHub Desktop.
Save seven1m/b876cfa610eba0df1ba7aa0837e937b8 to your computer and use it in GitHub Desktop.
Script to get latency for 3 AWS US regions
#!/bin/bash
# usage: ./awsping.sh | sort -n 2.7
# 39.93 us-east-2
# 44.95 us-east-1
# 64.89 us-west-2
function region_latency() {
local region="$1"
ping -c 1 ec2.$region.amazonaws.com &>/dev/null # throw away the first ping because DNS
local total=$(ping -c 2 ec2.$region.amazonaws.com | grep "time=" | sed -E 's/.*time=([0-9\.]+).*/\1/' | paste -sd+ - | bc)
bc <<< "scale=2; $total / 2"
}
latency=$(region_latency us-east-1)
echo "$latency us-east-1"
latency=$(region_latency us-east-2)
echo "$latency us-east-2"
latency=$(region_latency us-west-2)
echo "$latency us-west-2"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment