-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_drive.sh
More file actions
executable file
·52 lines (42 loc) · 1.53 KB
/
Copy pathtest_drive.sh
File metadata and controls
executable file
·52 lines (42 loc) · 1.53 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
#!/bin/sh
# path: /home/klassiker/.local/share/repos/shell/test_drive.sh
# author: klassiker [mrdotx]
# url: https://github.com/mrdotx/shell
# date: 2026-03-31T05:37:18+0200
# speed up script and avoid language problems by using standard c
LC_ALL=C
LANG=C
# auth can be something like sudo -A, doas -- or nothing,
# depending on configuration requirements
auth="${EXEC_AS_USER:-sudo}"
# rw_bytes (1M) * input_blocks (1024) = testfile (1gb)
rw_bytes=1M
input_blocks=1024
file_path="${1:-"$(pwd)"}/$(tr -cd 'a-f0-9' < /dev/urandom | head -c 16)"
# color variables for the interactive shell
tty -s \
&& reset="\033[0m" \
&& bold="\033[1m" \
&& blue="\033[94m" \
&& cyan="\033[96m"
# main
printf "%b%b ->%b drop caches [Y]es/[n]o: " \
"$bold" "$blue" "$reset" \
&& read -r drop_cache
printf "%b%b::%b %bwrite file (%s * %s)%b %b%s%b\n" \
"$bold" "$blue" "$reset" "$bold" "$rw_bytes" "$input_blocks" "$reset" \
"$cyan" "$file_path" "$reset"
dd if=/dev/zero of="$file_path" \
bs="$rw_bytes" count="$input_blocks" conv=fdatasync,notrunc status=progress
case "${drop_cache:-"y"}" in
y|Y|yes|Yes)
$auth sh -c "printf 3 > /proc/sys/vm/drop_caches"
;;
esac
printf "%b%b::%b %bread file%b %b%s%b\n" \
"$bold" "$blue" "$reset" "$bold" "$reset" "$cyan" "$file_path" "$reset"
dd if="$file_path" of=/dev/null \
bs="$rw_bytes" count="$input_blocks" status=progress
printf "%b%b::%b %bdelete file%b %b%s%b\n" \
"$bold" "$blue" "$reset" "$bold" "$reset" "$cyan" "$file_path" "$reset"
rm "$file_path"