run.sh 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/bash
  2. #
  3. # Run without argument for IPv4, and with any argument for IPv6..
  4. # Put your UUID here, and keep it secret!
  5. UUID="{{ uuid|default('00000000-0000-0000-0000-000000000000') }}"
  6. PEERFINDER="{{ peerfinder }}"
  7. NB_PINGS=5
  8. DELAY=10
  9. # This avoids synchronisation (everybody fetching jobs and running
  10. # measurements simultaneously)
  11. RANDOM_DELAY=20
  12. [ -z "$1" ] && FAMILY="ipv4" || FAMILY="ipv6"
  13. [ "$FAMILY" = "ipv4" ] && PING="ping -n -q" || PING="ping6 -n -q"
  14. while :
  15. do
  16. SLEEP=$((DELAY + RANDOM % RANDOM_DELAY))
  17. sleep "$SLEEP"
  18. curl "$PEERFINDER"/target/"$UUID"/"$FAMILY" > /tmp/"$FAMILY" 2> /dev/null
  19. read -r id ip < /tmp/"$FAMILY"
  20. # Avoid empty fields
  21. [ -z "$id" -o -z "$ip" ] && continue
  22. # Make sure "id" is an integer
  23. printf "%d" "$id" > /dev/null 2>&1 || continue
  24. # Parsing ping output, for Linux
  25. output="$($PING -c "$NB_PINGS" "$ip" | grep -A1 "packets transmitted")"
  26. echo $output | sed -e 's#^\([0-9]*\) packets transmitted, \([0-9]*\) received.*#\1\t\2#' > /tmp/"$FAMILY"_tmp1
  27. read sent received < /tmp/"$FAMILY"_tmp1
  28. if [ "$received" -eq 0 ]
  29. then
  30. args="avgrtt=NaN"
  31. echo "Target $id ($ip) is unreachable"
  32. else
  33. echo $output | sed -e 's#.*rtt min/avg/max/mdev = \(.*\)/\(.*\)/\(.*\)/\(.*\) ms$#\1\t\2\t\3\t\4#' > /tmp/"$FAMILY"_tmp2
  34. read minrtt avgrtt maxrtt jitter < /tmp/"$FAMILY"_tmp2
  35. [ -z "$avgrtt" ] && continue
  36. echo "RTT to target $id ($ip) is $avgrtt"
  37. args="minrtt=${minrtt}&avgrtt=${avgrtt}&maxrtt=${maxrtt}&jitter=${jitter}"
  38. fi
  39. curl -d "target=${id}&probes_sent=${sent}&probes_received=${received}&${args}" "$PEERFINDER"/result/report/"$UUID"
  40. done