From: Samir Benmendil Date: Sun, 22 May 2016 20:44:20 +0000 (+0100) Subject: bin: Add speedtest script X-Git-Url: https://git.rmz.io/dotfiles.git/commitdiff_plain/19e1d5f113bff40fbe6a4f4ab3136916ca943644 bin: Add speedtest script --- diff --git a/bin/speedtest b/bin/speedtest new file mode 100755 index 0000000..29b30e2 --- /dev/null +++ b/bin/speedtest @@ -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"