-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_broadband.sh
More file actions
executable file
·63 lines (54 loc) · 1.69 KB
/
Copy pathtest_broadband.sh
File metadata and controls
executable file
·63 lines (54 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/bin/sh
# path: /home/klassiker/.local/share/repos/shell/test_broadband.sh
# author: klassiker [mrdotx]
# url: https://github.com/mrdotx/shell
# date: 2026-05-18T05:29:12+0200
# speed up script and avoid language problems by using standard c
LC_ALL=C
LANG=C
# config
input_delimiter="#"
retries=5
delay=10
csv="$HOME/Public/broadband/test.csv"
header="Date Time Ping Down Up Host IP Km Server ID Sponsor"
# helper
get_value() {
printf "%s" "$1" \
| cut -d "$input_delimiter" -f"$2"
}
round() {
# WORKAROUND: printf "%.0f" not completely converted in the dash shell
awk "BEGIN {printf \"%.$1f\", $2}"
}
# direct execution options
case $* in
*"--list"*|*"--help"*|*"--version"*)
speedtest-cli "$@"
exit
;;
esac
# main
while [ "${error:-1}" -gt 0 ] && [ $retries -gt 0 ]; do
test_result=$(speedtest-cli --csv --csv-delimiter "$input_delimiter" "$@")
error=$?
retries=$((retries-1))
[ $retries -gt 0 ] \
|| exit $error
[ $error -gt 0 ] \
&& sleep $delay
done
[ -s "$csv" ] \
|| printf "%s\n" "$header" > "$csv"
printf "%s %s %s %s %s %s %s %s %s %s %s\n" \
"$(date -d "$(get_value "$test_result" 4)" +"%d.%m.%Y")" \
"$(date -d "$(get_value "$test_result" 4)" +"%H:%M:%S")" \
"$(get_value "$test_result" 6)" \
"$(round 2 "$(printf "%s/1000000\n" "$(get_value "$test_result" 7)" | bc -l)")" \
"$(round 2 "$(printf "%s/1000000\n" "$(get_value "$test_result" 8)" | bc -l)")" \
"$(uname -n)" \
"$(get_value "$test_result" 10)" \
"$(round 2 "$(get_value "$test_result" 5)")" \
"$(get_value "$test_result" 3)" \
"$(get_value "$test_result" 1)" \
"$(get_value "$test_result" 2)" >> "$csv"