Browse Source

Add silent (-s) flag to curl to hide transfer progress but allow errors to still show.
Create cronjob version of script without the while loop.

Jon Lundy 10 years ago
parent
commit
3324c3104b
2 changed files with 53 additions and 2 deletions
  1. 51 0
      templates/cron.sh
  2. 2 2
      templates/run.sh

+ 51 - 0
templates/cron.sh

@@ -0,0 +1,51 @@
+#!/bin/bash
+#
+# Measurement script for the dn42 peer finder, see http://peerfinder.polynome.dn42
+# Dependencies: curl, sed, ping
+#
+# Run without argument for IPv4-only, and with an argument for IPv6-only, e.g.
+#
+#   ./script.sh ipv6
+
+# Put your UUID here, and keep it secret!
+UUID="{{ uuid|default('00000000-0000-0000-0000-000000000000') }}"
+PEERFINDER="{{ peerfinder }}"
+NB_PINGS=5
+
+# This avoids synchronisation (everybody fetching jobs and running
+# measurements simultaneously)
+RANDOM_DELAY=30
+
+[ -z "$1" ] && FAMILY="ipv4" || FAMILY="ipv6"
+
+[ "$FAMILY" = "ipv4" ] && PING="ping -n -q" || PING="ping6 -n -q"
+
+SLEEP=$((RANDOM % RANDOM_DELAY))
+sleep "$SLEEP"
+curl -s "$PEERFINDER"/target/"$UUID"/"$FAMILY" > /tmp/"$FAMILY"
+read -r id ip < /tmp/"$FAMILY"
+
+# Avoid empty fields
+[ -z "$id" -o -z "$ip" ] && exit
+
+# Make sure "id" is an integer
+printf "%d" "$id" > /dev/null 2>&1 || exit
+
+# Parsing ping output, for Linux
+output="$($PING -c "$NB_PINGS" "$ip" | grep -A1 "packets transmitted")"
+echo $output | sed -e 's#^\([0-9]*\) packets transmitted, \([0-9]*\) received.*#\1\t\2#' > /tmp/"$FAMILY"_tmp1
+read sent received < /tmp/"$FAMILY"_tmp1
+if [ "$received" -eq 0 ]
+then
+    args="avgrtt=NaN"
+    echo "Target $id ($ip) is unreachable"
+else
+    echo $output | sed -e 's#.*rtt min/avg/max/mdev = \(.*\)/\(.*\)/\(.*\)/\(.*\) ms$#\1\t\2\t\3\t\4#' > /tmp/"$FAMILY"_tmp2
+    read minrtt avgrtt maxrtt jitter < /tmp/"$FAMILY"_tmp2
+    [ -z "$avgrtt" ] && exit
+    echo "RTT to target $id ($ip) is $avgrtt"
+    args="minrtt=${minrtt}&avgrtt=${avgrtt}&maxrtt=${maxrtt}&jitter=${jitter}"
+fi
+
+# Report results back to peerfinder
+curl -s -d "target=${id}&probes_sent=${sent}&probes_received=${received}&${args}" "$PEERFINDER"/result/report/"$UUID"

+ 2 - 2
templates/run.sh

@@ -24,7 +24,7 @@ while :
 do
     SLEEP=$((DELAY + RANDOM % RANDOM_DELAY))
     sleep "$SLEEP"
-    curl "$PEERFINDER"/target/"$UUID"/"$FAMILY" > /tmp/"$FAMILY" 2> /dev/null
+    curl -s "$PEERFINDER"/target/"$UUID"/"$FAMILY" > /tmp/"$FAMILY"
     read -r id ip < /tmp/"$FAMILY"
     # Avoid empty fields
     [ -z "$id" -o -z "$ip" ] && continue
@@ -45,5 +45,5 @@ do
         echo "RTT to target $id ($ip) is $avgrtt"
         args="minrtt=${minrtt}&avgrtt=${avgrtt}&maxrtt=${maxrtt}&jitter=${jitter}"
     fi
-    curl -d "target=${id}&probes_sent=${sent}&probes_received=${received}&${args}" "$PEERFINDER"/result/report/"$UUID"
+    curl -s -d "target=${id}&probes_sent=${sent}&probes_received=${received}&${args}" "$PEERFINDER"/result/report/"$UUID"
 done