-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloadtest.sh
51 lines (42 loc) · 897 Bytes
/
loadtest.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
#!/bin/sh
while getopts ":u:c:" opt; do
case $opt in
u) url="$OPTARG"
;;
c) count="$OPTARG"
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
if [ -z "$url" ]
then
echo "Please include a URL (-u) to test."
exit
fi
if [ -z "$count" ]
then
count="10"
fi
echo ""
printf "Load Time Testing: %s\n" "$url"
sum=0
max=0
min=100
for ((i=0; i<count; i++)); do
result=$(curl -o /dev/null -s -w "%{time_total}\n" "$url")
sum=$(echo $s | awk "{print (($result+$sum))}")
if (( $(echo "$max $result" | awk '{ print ($1 < $2)}') )); then
max="$result"
fi
if (( $(echo "$min $result" | awk '{ print ($1 > $2)}') )); then
min="$result"
fi
done
avg=$(echo $a | awk "{print (($sum/$count))}")
echo "************************"
echo "Total Test Time: $sum"
echo "Average Load Time: $avg"
echo "Max Load Time: $max"
echo "Min Load Time: $min"
echo ""