Comment 6 for bug 317065

Revision history for this message
polvi (alex-polvi) wrote :

I couldn't come up with any better ideas, so here is a bash implementation of the traceroute method. Seems to work:

#!/bin/bash

A="ec2-75-101-201-203.compute-1.amazonaws.com" # node in us-east-1a
B="ec2-75-101-228-202.compute-1.amazonaws.com" # node in us-east-1b
C="ec2-174-129-138-71.compute-1.amazonaws.com" # node in us-east-1c

for mirror in $A $B $C; do
  HOPS="`tracepath -n $mirror | grep hops | awk '{ print $5 }'`"
  # checking for an int is not pretty in bash
  [ "$HOPS" -gt 0 ] 2>&- && echo "$HOPS $mirror"
done | sort -n | head -n 1 | awk '{ print $2 }'

The host that ran this command was on us-east-1c, and selected $C correctly each time.

root@ubuntu:~# ./close-host.sh
ec2-174-129-138-71.compute-1.amazonaws.com

Example tracepath output:

ec2-75-101-201-203.compute-1.amazonaws.com
 1: domU-12-31-39-00-9D-23.compute-1.internal (10.254.162.209) 0.092ms pmtu 1500
 1: dom0-10-254-160-160.compute-1.internal (10.254.160.160) 0.099ms
 1: dom0-10-254-160-160.compute-1.internal (10.254.160.160) 0.055ms
 2: 10.254.160.2 (10.254.160.2) 0.979ms
 3: ec2-75-101-160-160.compute-1.amazonaws.com (75.101.160.160) 0.522ms
 4: othr-216-182-232-13.usma2.compute.amazonaws.com (216.182.232.13) 1.077ms
 5: ec2-75-101-160-33.compute-1.amazonaws.com (75.101.160.33) 1.171ms
 6: dom0-10-252-128-156.compute-1.internal (10.252.128.156) 1.037ms
 7: domU-12-31-38-00-7D-64.compute-1.internal (10.252.130.146) 1.074ms reached
     Resume: pmtu 1500 hops 7 back 58

ec2-75-101-228-202.compute-1.amazonaws.com
 1: domU-12-31-39-00-9D-23.compute-1.internal (10.254.162.209) 0.055ms pmtu 1500
 1: dom0-10-254-160-160.compute-1.internal (10.254.160.160) 0.061ms
 1: dom0-10-254-160-160.compute-1.internal (10.254.160.160) 0.053ms
 2: 10.254.160.2 (10.254.160.2) 0.728ms
 3: ec2-75-101-160-176.compute-1.amazonaws.com (75.101.160.176) 0.397ms
 4: othr-216-182-232-15.usma2.compute.amazonaws.com (216.182.232.15) 0.823ms
 5: othr-216-182-224-18.usma1.compute.amazonaws.com (216.182.224.18) 1.191ms
 6: ec2-75-101-160-113.compute-1.amazonaws.com (75.101.160.113) 1.434ms
 7: ip-10-251-124-167.ec2.internal (10.251.124.167) 1.094ms
 8: ip-10-251-127-65.ec2.internal (10.251.127.65) 1.201ms reached
     Resume: pmtu 1500 hops 8 back 57

ec2-174-129-138-71.compute-1.amazonaws.com
 1: domU-12-31-39-00-9D-23.compute-1.internal (10.254.162.209) 0.064ms pmtu 1500
 1: dom0-10-254-160-160.compute-1.internal (10.254.160.160) 0.069ms
 1: dom0-10-254-160-160.compute-1.internal (10.254.160.160) 0.055ms
 2: 10.254.160.2 (10.254.160.2) 0.889ms
 3: dom0-10-254-164-152.compute-1.internal (10.254.164.152) 0.305ms
 4: domU-12-31-39-00-A1-A3.compute-1.internal (10.254.166.81) 0.467ms reached
     Resume: pmtu 1500 hops 4 back 61