-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
executable file
·129 lines (100 loc) · 2.94 KB
/
entrypoint.sh
File metadata and controls
executable file
·129 lines (100 loc) · 2.94 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/sh
rm -rf /tmp/.X1-lock
Xvfb :1 -dpi 72 -deferglyphs all -screen scrn 1920x1080x24 > /dev/null 2>&1 &
export DISPLAY=:1
echo "--------------------------------------------------------------------------------------------------------"
echo "Timezone:"
timezone="Europe/Vienna"
if [ -n "$TIMEZONE" ]; then
timezone=$TIMEZONE
echo "$TIMEZONE"
else
echo "use default timezone: $TIMEZONE"
fi
ln -sf "/usr/share/zoneinfo/$TIMEZONE" /etc/localtime
echo ""
echo "------------------------------------- `date` -------------------------------------"
echo ""
# seconds
seconds=3600 # every hour --> default value
# read interval env
if [ -n "$RUNEVERYNMINUTES" ]; then
seconds=$RUNEVERYNMINUTES
else
echo "env 'RUNEVERYNMINUTES' not set --> using default value: $seconds"
fi
echo "intervall set to $seconds seconds"
echo "values are in bits (bit/s)"
echo ""
echo "--------------------------------------------------------------------------------------------------------"
echo ""
speedtestversion="$(speedtest-cli --version)"
echo "${speedtestversion}"
echo ""
echo "--------------------------------------------------------------------------------------------------------"
echo ""
# Print CSV Header
header="$(speedtest-cli --csv-header)"
echo "${header}"
# the to store the data
DATE=`date +%Y-%m`
csvFile="/data/${DATE}.csv"
# create file if it does not exist and add header
if [ ! -f ${csvFile} ]; then
# echo "create file: " + ${csvFile}
# add header to .csv file
echo "${header}" >> $csvFile
fi
# Remove blank lines in csv (fix /plot.py error index out of range)
sed '/^$/d' $csvFile > $csvFile.out
mv $csvFile.out $csvFile
# Run every n seconds
speedtest()
{
#speedtest-cli --csv
output="$(speedtest-cli --timeout 60 --secure --csv)"
# echo "${output}"
# if there is a cli error, the output is "", so do not append it to the csv
lengthOfString=${#output}
# echo "lengthOfString: ${lengthOfString}"
if [ "$lengthOfString" -gt "1" ]; then
down="$(cut -d',' -f7 <<<"$output")"
up="$(cut -d',' -f8 <<<"$output")"
retry=false
if test "$down" = "0.0"
then
echo "Download error --> retry!"
retry=true
fi
if test "$up" = "0.0"
then
echo "Upload error --> retry!"
retry=true
fi
if [ $retry == true ]
then
echo " down: ${down}"
echo " up: ${up}"
echo "..."
speedtest
else
# get ISO8601 string from output
ISO8601="$(cut -d',' -f4 <<<"$output")"
# echo "${ISO8601}"
# local time
now=`date +%Y-%m-%dT%H:%M:%S`
# replace in string
outputWithLocaltime="${output/${ISO8601}/$now}"
echo "${outputWithLocaltime}"
echo "${outputWithLocaltime}" >> $csvFile
echo "--------------------------------------------------------------------------------------------------------"
python /plot.py
fi
fi
}
# run test
while true
do
speedtest
sleep $seconds
done