-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun.sh
executable file
·57 lines (51 loc) · 1.49 KB
/
run.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
#!/bin/bash
if ! [ -x "$(type -P iperf3)" ]; then
echo "ERROR: script requires iperf"
echo "If you have it, perhaps you don't have permissions to run it, try 'sudo $(basename $0)' and make sure it's in \$PATH"
exit 1
fi
if [ "$#" -ne "4" ]; then
echo "ERROR: script needs four arguments, where:"
echo
echo "1. Number of times to repeat test (e.g. 10 or 0 for infinite)"
echo "2. Host running 'iperf3 -s' (e.g. somehost)"
echo "3. Port of host (normally 5201)"
echo "4. Time to wait between tests (in seconds)"
echo
echo "Example:"
echo " $(basename $0) 10 <host> <port> 60"
echo
echo "The above will run iperf3 10 times with 60 seconds of sleep."
exit 1
else
runs=$1
host=$2
port=$3
zzzz=$4
fi
log=iperf.$host.log
output=iperf.${host}.out
tmpout=iperf.${host}.tmp
if [ -f $log ]; then
echo removing $log
rm $log
fi
if [ -f $tmpout ]; then
echo removing $tmpout
rm $tmpout
fi
echo "Running iperf3 pointed at ${host}:${port}, ${runs} times with ${zzzz} seconds sleep between cycles, ${zzzz} seconds of sleep between upload/download tests"
run=1
while [ $run -le $runs -o $runs -eq 0 ]
do
printf "${run}/${runs}"
iperf3 --client ${host} --port ${port} --json --logfile ${tmpout} -O 3 -i 0
cat ${tmpout} | json-minify >> ${output} && rm ${tmpout}
sleep ${zzzz}
iperf3 --client ${host} --port ${port} --json --logfile ${tmpout} -O 3 -i 0 -R
cat ${tmpout} | json-minify >> ${output} && rm ${tmpout}
run=$[$run+1]
sleep ${zzzz}
printf "..."
done
echo "Done"