Last active
November 8, 2021 18:56
-
-
Save seven1m/b876cfa610eba0df1ba7aa0837e937b8 to your computer and use it in GitHub Desktop.
Script to get latency for 3 AWS US regions
This file contains 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
#!/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