]> git.rmz.io Git - dotfiles.git/blob - bin/speedtest
Merge branch 'remove-lazyvim'
[dotfiles.git] / bin / speedtest
1 #!/bin/bash
2
3 get_speeds() {
4 # returns ping= download= upload=
5 librespeed-cli --server 43 --simple 2>&1 | perl -pe 's/(\w+)(?: \w+)?:\s+([0-9]+\.[0-9]+).*/\L\1=\2/p'
6 }
7
8 get_xx_bytes() {
9 local xx_bytes=( $(ssh -q root@192.168.1.1 -p2222 cat /sys/class/net/$intf/statistics/{r,t}x_bytes) )
10 echo rx_bytes=${xx_bytes[0]}
11 echo tx_bytes=${xx_bytes[1]}
12 }
13
14 while [[ $# > 1 ]]; do
15 case "$1" in
16 -o|--output) out="$2"; shift 2;;
17 -s|--server) server="$2"; shift 2;;
18 -i|--interface) intf="$2"; shift 2;;
19 esac
20 done
21
22 out=${out:-speedtest.log}
23 intf=${intf:-vlan1}
24
25 if [[ ! -e "$out" ]]; then
26 echo "date,ping,download,upload" > "$out"
27 fi
28
29 date=$(date --rfc-3339=seconds -u)
30 source <(get_speeds)
31 printf "%s,%.3f,%.3f,%.3f\n" "$date" "$ping" "$download" "$upload" >> "$out"