-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnetspeed.sh
More file actions
executable file
·68 lines (47 loc) · 1.97 KB
/
netspeed.sh
File metadata and controls
executable file
·68 lines (47 loc) · 1.97 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
64
65
66
67
68
#!/bin/bash
# Pre-requisites: `speedtest-cli'
# Usage:
# `netspeed CYCLES[number of tests]' [anything for upload][optional].
CYCLES=$1
# Default is 2 cycles
[ -n "$CYCLES" ] || CYCLES=2
rm /tmp/upspeed 2>/dev/null
echo "** Download Speed **" > /tmp/downspeed
echo $(date) >> /tmp/downspeed
echo '' >> /tmp/downspeed
for((i=0;i<$CYCLES;i++));do
(command -v speedtest-cli >/dev/null && speedtest-cli --no-upload |grep ^Download |tee -a /tmp/downspeed)
done
# Update number of cycles based on results. This might be less than or equal to
# `CYCLES' defined earlier.
ROUNDS=$(cat /tmp/downspeed | grep "^Download: [0-9.]\{1,4\}" | wc -l)
if [ "$ROUNDS" = "0" ]; then
FAILMSG="Failed to perform speedtest-cli."
notify-send "$FAILMSG"
echo "$FAILMSG"
exit 1
fi
# Calculating average download speed.
echo "" >> /tmp/downspeed
echo -n "Average download speed in Mbps for $ROUNDS cycle is " >> /tmp/downspeed
echo "scale=2; (($(cat /tmp/downspeed | sed 's/.* \([0-9]*\.[0-9]*\) .*/\1/p' -n | paste -sd '+'))/$ROUNDS)" | bc >> /tmp/downspeed
notify-send "Download speed results.
$(cat /tmp/downspeed)"
# Follow same procedure used above for upload speed also.
# Give any argument after number of cycles to log upload speed.
if [ $2 ]; then
echo "** Upload Speed **" >> /tmp/upspeed
echo $(date) >> /tmp/upspeed
echo '' >> /tmp/upspeed
for((i=0;i<$CYCLES;i++));do
command -v speedtest-cli >/dev/null && speedtest-cli --no-download |grep ^Upload |tee -a /tmp/upspeed
done
# Update number of cycles based on results. This might be less than or equal to
# `CYCLES' defined earlier.
ROUNDS=$(cat /tmp/upspeed | grep "^Upload: [0-9.]\{1,4\}" | wc -l)
echo "" >> /tmp/upspeed
echo -n "Average upload speed in Mbps for $ROUNDS cycle is " >> /tmp/upspeed
echo "scale=2; (($(cat /tmp/upspeed | sed 's/.* \([0-9]*\.[0-9]*\) .*/\1/p' -n | paste -sd '+'))/$ROUNDS)" | bc >> /tmp/upspeed
notify-send "Upload speed results.
$(cat /tmp/upspeed)"
fi