-
Notifications
You must be signed in to change notification settings - Fork 0
/
cableReboot.sh
executable file
·82 lines (64 loc) · 1.38 KB
/
cableReboot.sh
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env bash
set -o pipefail
set -o errexit
set -o nounset
reps=3
total=0
speed=0
log() { # classic logger
local prefix
prefix="[$(date +%Y/%m/%d\ %H:%M:%S)]: "
echo "${prefix} $*" >&2
}
speedTest() {
size=$1
speed=$(wget http://testmy.net/dl-${size}MB --delete-after --report-speed=bits -O /tmp/speedcheck.$$ 2>&1 | grep '[KM]b' | sed 's/^.*(//;s/).*//')
units=$(echo "${speed}" | awk '{print $2}')
speed=$(echo "${speed}" | awk '{print $1}' | awk -F. '{print $1}')
if [ -z "${speed}" ];
then
speed=0
fi
if [[ "${units}" == "Kb/s" ]];
then
speed=$((speed/1024))
fi
echo ${speed}
}
for (( n=1; n<=reps; n++ ))
do
log "INFO" "Starting run: $n"
if [[ $n == 1 ]];
then
size=3
else
size=${total}+1
fi
speed=$(speedTest ${size})
total=$((total + speed))
log "INFO" "Run ${n} : ${speed}"
if [[ ${n} -lt ${reps} ]];
then
sleep 10
fi
done
average=$(( total/reps ))
log "INFO" "Average : ${average}"
if [[ ${average} -lt 20 ]];
then
log "INFO" "Running one last check"
speed=$(speedTest 5)
log "INFO" "Final : ${speed}"
if [[ ${speed} -lt 15 ]];
then
log "INFO" "Restarting modem"
wget --post-data="Rebooting=1" -q -O - http://192.168.100.1/goform/RgConfiguration.pl > /dev/null 2>&1
log "INFO" "Done"
fi
fi
temp_files=(/tmp/speedcheck.*)
if [ -e "${temp_files[0]}" ];
then
rm /tmp/speedcheck.*
fi
exit