#!/bin/bash get_speeds() { # returns ping= download= upload= librespeed-cli --server 43 --simple 2>&1 | perl -pe 's/(\w+)(?: \w+)?:\s+([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"