Skip to content

Instantly share code, notes, and snippets.

@linuxmalaysia
Last active December 23, 2023 00:16
Show Gist options
  • Save linuxmalaysia/6d9dbe11dfe287a91d189077b28804d0 to your computer and use it in GitHub Desktop.
Save linuxmalaysia/6d9dbe11dfe287a91d189077b28804d0 to your computer and use it in GitHub Desktop.
Random create files with in current directory the script running. The dd output is use to compare the write speed.
#!/bin/bash
# Haris - 20231223
# Make sure you have enough disk space (max 200GB).
# Randomly create files inside./files, within current directory of this script.
# The dd output is used to compare the write speed.
# Ensure variables are declared before use.
declare -i min=5 # min size (GB)
declare -i max=10 # max size (GB)
declare -i nofiles=10 # number of files
# Create the output directory if it doesn't exist
mkdir -p ./files
# Generate a unique filename for the combined output
combined_output_file="./files/combined_output_$(date +%Y%m%d_%H%M%S).txt"
for i in $(seq 1 "$nofiles")
do
# Ensure random size is within the valid range
size=$(( (RANDOM % (max - min + 1)) + min ))
# Calculate the size in blocks for dd (1 GB = 1024 MB)
block_size=$(( size * 1024 ))
# Print a message to the screen (not redirected)
echo "Generating file $i with size $size GB..." | tee -a "$combined_output_file"
# Redirect dd output to the combined file only
dd bs=$block_size"M" count=1 if=/dev/urandom of="./files/file$i" 2>&1 | tee -a "$combined_output_file"
# Print a message to the screen (not redirected)
echo "dd output for file $i saved to combined output file"
done
# Display the combined output on the screen
echo "---------------------------------------------------------"
echo "Combined dd output:"
cat "$combined_output_file"
@linuxmalaysia
Copy link
Author

linuxmalaysia commented Dec 23, 2023

Example of output of lvm-thin on iscsi device:

[root@node01 data]# cat files/combined_output_20231223_080021.txt
Generating file 1 with size 5 GB...
0+1 records in
0+1 records out
2147479552 bytes (2.1 GB, 2.0 GiB) copied, 47.4722 s, 45.2 MB/s
Generating file 2 with size 8 GB...
0+1 records in
0+1 records out
2147479552 bytes (2.1 GB, 2.0 GiB) copied, 47.4007 s, 45.3 MB/s
Generating file 3 with size 10 GB...
0+1 records in
0+1 records out
2147479552 bytes (2.1 GB, 2.0 GiB) copied, 47.4181 s, 45.3 MB/s
Generating file 4 with size 9 GB...
0+1 records in
0+1 records out
2147479552 bytes (2.1 GB, 2.0 GiB) copied, 47.4972 s, 45.2 MB/s
Generating file 5 with size 6 GB...
0+1 records in
0+1 records out
2147479552 bytes (2.1 GB, 2.0 GiB) copied, 47.4178 s, 45.3 MB/s
Generating file 6 with size 10 GB...
0+1 records in
0+1 records out
2147479552 bytes (2.1 GB, 2.0 GiB) copied, 47.408 s, 45.3 MB/s
Generating file 7 with size 6 GB...
0+1 records in
0+1 records out
2147479552 bytes (2.1 GB, 2.0 GiB) copied, 47.4018 s, 45.3 MB/s
Generating file 8 with size 6 GB...
0+1 records in
0+1 records out
2147479552 bytes (2.1 GB, 2.0 GiB) copied, 47.3849 s, 45.3 MB/s
Generating file 9 with size 7 GB...
0+1 records in
0+1 records out
2147479552 bytes (2.1 GB, 2.0 GiB) copied, 47.3685 s, 45.3 MB/s
Generating file 10 with size 8 GB...
0+1 records in
0+1 records out
2147479552 bytes (2.1 GB, 2.0 GiB) copied, 47.7571 s, 45.0 MB/s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment