#!/bin/bash # Check if the device argument is provided if [ -z "$1" ]; then echo "Usage: $0 /dev/sda1" exit 1 fi # Set the path to your USB mount point USB_PATH="$1" # Set different file sizes (in MB) FILE_SIZES=(10 100 1000 10000) # Set block size (1M block size for testing) BLOCK_SIZE="1M" # Set the number of iterations for each file size ITERATIONS=3 # Start benchmarking echo "Starting USB performance benchmark for device: $USB_PATH" # Loop through the different file sizes for SIZE in "${FILE_SIZES[@]}"; do echo "-------------------------------------------" echo "Testing with file size: $SIZE MB" # Convert size from MB to bytes for dd SIZE_IN_BYTES=$((SIZE * 1024 * 1024)) # Loop for the specified number of iterations for i in $(seq 1 $ITERATIONS); do echo "Iteration $i: Testing write speed..." # Test write speed WRITE_SPEED=$(sudo dd if=/dev/zero of="$USB_PATH/testfile" bs=$BLOCK_SIZE count=$SIZE oflag=direct 2>&1 | grep -o '[0-9\.]* MB/s' | tail -n 1) echo "Iteration $i: Write speed = $WRITE_SPEED" echo "Iteration $i: Testing read speed..." # Test read speed READ_SPEED=$(sudo dd if="$USB_PATH/testfile" of=/dev/null bs=$BLOCK_SIZE 2>&1 | grep -o '[0-9\.]* MB/s' | tail -n 1) echo "Iteration $i: Read speed = $READ_SPEED" echo "-------------------------------------------" # Sleep for 1 second between iterations to prevent overload sleep 1 done # Clean up the test file after benchmarking sudo rm -f "$USB_PATH/testfile" done echo "Benchmarking complete!"