Last active
December 23, 2023 00:16
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of output of lvm-thin on iscsi device: