Skip to content

Instantly share code, notes, and snippets.

@PaulGoldschmidt
Created June 26, 2023 10:05
Show Gist options
  • Save PaulGoldschmidt/15d30b58f6f1fc5ba4c2f7b3f54db063 to your computer and use it in GitHub Desktop.
Save PaulGoldschmidt/15d30b58f6f1fc5ba4c2f7b3f54db063 to your computer and use it in GitHub Desktop.
A small bash script that logs a S.M.A.R.T.-Test and Benchmark to a file with date and drive UUID. Tested under Ubuntu 22.04 LTS.
#!/bin/bash
# AUTO-TESTER FOR HDDs - Logs a S.M.A.R.T.-Test and Benchmark to a file with date and drive UUID. By Paul Goldschmidt, 2023-06-26 (HEIDELBERG)
# Ask for a HDD to test
read -p "Enter HDD to test (e.g., /dev/sdb): " HDD
# Perform a short smarttest
echo "Starting S.M.A.R.T. short test on $HDD..."
sudo smartctl -t short $HDD
echo "Waiting for S.M.A.R.T. test to complete..."
sleep 75 # Wait for 75 seconds for the short test to complete
# Get the test results
echo "Getting full S.M.A.R.T. test results..."
SMART_RESULTS=$(sudo smartctl -a $HDD)
# Benchmark the disk
echo "Starting disk benchmark..."
BENCHMARK_RESULTS=$(sudo hdparm -Tt $HDD)
# Get disk UUID
DISK_UUID=$(lsblk -no UUID $HDD)
# Prepare output file
DATE=$(date +%Y-%m-%d_%H-%M-%S)
OUTPUT_FILE="hdd-test_${DATE}_${DISK_UUID}.txt"
# Write all the test results to a file
echo "Writing test results to $OUTPUT_FILE..."
echo "S.M.A.R.T. Test Results for $HDD:" > $OUTPUT_FILE
echo "$SMART_RESULTS" >> $OUTPUT_FILE
echo "" >> $OUTPUT_FILE
echo "Benchmark Results for $HDD:" >> $OUTPUT_FILE
echo "$BENCHMARK_RESULTS" >> $OUTPUT_FILE
echo "Test complete. Results saved to $OUTPUT_FILE."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment