]> git.rmz.io Git - dotfiles.git/commitdiff
bin: Add speedtest script
authorSamir Benmendil <me@rmz.io>
Sun, 22 May 2016 20:44:20 +0000 (21:44 +0100)
committerSamir Benmendil <me@rmz.io>
Sun, 22 May 2016 20:44:20 +0000 (21:44 +0100)
bin/speedtest [new file with mode: 0755]

diff --git a/bin/speedtest b/bin/speedtest
new file mode 100755 (executable)
index 0000000..29b30e2
--- /dev/null
@@ -0,0 +1,31 @@
+#!/bin/bash
+
+get_speeds() {
+    # returns ping= download= upload=
+    speedtest-cli --simple | sed -rn 's/(\w+): ([0-9]+\.[0-9]+).*/\L\1=\2/p'
+}
+
+get_xx_bytes() {
+    local xx_bytes=( $(ssh -q root@192.168.1.1 -p2222 cat /sys/class/net/$intf/statistics/{r,t}x_bytes) )
+    echo rx_bytes=${xx_bytes[0]}
+    echo tx_bytes=${xx_bytes[1]}
+}
+
+while [[ $# > 1 ]]; do
+    case "$1" in
+        -o|--output)    out="$2";    shift 2;;
+        -s|--server)    server="$2"; shift 2;;
+        -i|--interface) intf="$2";   shift 2;;
+    esac
+done
+
+out=${out:-speedtest.log}
+intf=${intf:-vlan1}
+
+if [[ ! -e "$out" ]]; then
+    echo "date,ping,download,upload" > "$out"
+fi
+
+date=$(date --rfc-3339=seconds -u)
+source <(get_speeds)
+printf "%s,%.3f,%.3f,%.3f\n" "$date" "$ping" "$download" "$upload" >> "$out"