-
Notifications
You must be signed in to change notification settings - Fork 0
/
diskspeedr.sh
executable file
·44 lines (33 loc) · 949 Bytes
/
diskspeedr.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
#!/usr/bin/env bash
set -euf -o pipefail
# s specific stuff
if ${s_child:-false}; then
dd
fi
if [[ ${1:-} == "help" ]]; then
echo " usage: ${0} <file or device> <block size [100M]> <block count [10]>"
exit
fi
function clean() {
printf "\ncleaning up...\n"
rm "${testfile}"
rm "${randfile}"
}
export -f clean
if [[ -z ${1:-} ]]; then
${0} help
exit 1
fi
trap "clean \"${1}\"" TERM INT HUP EXIT
testfile="${1}"
randfile="$(mktemp)"
bs=${2:-100M}
count=${3:-10}
pcount=$(((count * 110) / 100))
printf "=> creating test file in memory...\n"
dd if=/dev/urandom of=${randfile} iflag=fullblock bs=${bs} count=${pcount} status=progress
printf "\n=> preparation finished\n"
printf "\n=> testing write speed\n"
dd if=${randfile} of=${testfile} iflag=fullblock oflag=direct bs=${bs} count=${count} status=progress
printf "\n=> testing read speed\n"
dd if=${testfile} of=/dev/null iflag=direct bs=${bs} count=${count} status=progress