mirror of
https://github.com/Spearfoot/disk-burnin-and-testing.git
synced 2025-12-11 13:53:21 +00:00
decouple by splitting code into smaller functions
This commit is contained in:
159
disk-burnin.sh
159
disk-burnin.sh
@@ -36,15 +36,15 @@ EXAMPLES
|
|||||||
$(basename "$0") -fo ~/burn-in-logs sdc
|
$(basename "$0") -fo ~/burn-in-logs sdc
|
||||||
run in destructive, non-dry mode on disk /dev/sdc and
|
run in destructive, non-dry mode on disk /dev/sdc and
|
||||||
write the log files to ~/burn-in-logs directory
|
write the log files to ~/burn-in-logs directory
|
||||||
|
"
|
||||||
EXIT STATUS
|
readonly USAGE_2=\
|
||||||
|
"EXIT STATUS
|
||||||
exit 0: script finishes successfully
|
exit 0: script finishes successfully
|
||||||
exit 2: dependencies are missing
|
exit 2: dependencies are missing
|
||||||
not running as 'root'
|
not running as 'root'
|
||||||
illegal options are provided
|
illegal options are provided
|
||||||
"
|
|
||||||
readonly USAGE_2=\
|
NOTES
|
||||||
"NOTES
|
|
||||||
Be warned that:
|
Be warned that:
|
||||||
|
|
||||||
1> The script runs badblocks in destructive mode, which erases any data
|
1> The script runs badblocks in destructive mode, which erases any data
|
||||||
@@ -358,6 +358,76 @@ log_header()
|
|||||||
log_info "+-----------------------------------------------------------------------------"
|
log_info "+-----------------------------------------------------------------------------"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
##################################################
|
||||||
|
# Ensure log directory exists and remove old logs.
|
||||||
|
# Globals:
|
||||||
|
# LOG_DIR
|
||||||
|
# LOG_FILE
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
##################################################
|
||||||
|
init_log() {
|
||||||
|
mkdir -p -- "${LOG_DIR}" || exit 2
|
||||||
|
[ -e "${LOG_FILE}" ] && rm -- "${LOG_FILE}"
|
||||||
|
}
|
||||||
|
|
||||||
|
##################################################
|
||||||
|
# Remove redundant messages from log.
|
||||||
|
# Globals:
|
||||||
|
# LOG_FILE
|
||||||
|
# OS_FLAVOR
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
##################################################
|
||||||
|
cleanup_log() {
|
||||||
|
if [ "${OS_FLAVOR}" = "Linux" ]; then
|
||||||
|
sed -i -e '/Copyright/d' "${LOG_FILE}"
|
||||||
|
sed -i -e '/=== START OF READ/d' "${LOG_FILE}"
|
||||||
|
sed -i -e '/SMART Attributes Data/d' "${LOG_FILE}"
|
||||||
|
sed -i -e '/Vendor Specific SMART/d' "${LOG_FILE}"
|
||||||
|
sed -i -e '/SMART Error Log Version/d' "${LOG_FILE}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${OS_FLAVOR}" = "FreeBSD" ]; then
|
||||||
|
sed -i '' -e '/Copyright/d' "${LOG_FILE}"
|
||||||
|
sed -i '' -e '/=== START OF READ/d' "${LOG_FILE}"
|
||||||
|
sed -i '' -e '/SMART Attributes Data/d' "${LOG_FILE}"
|
||||||
|
sed -i '' -e '/Vendor Specific SMART/d' "${LOG_FILE}"
|
||||||
|
sed -i '' -e '/SMART Error Log Version/d' "${LOG_FILE}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
##################################################
|
||||||
|
# Log runtime information about current burn-in.
|
||||||
|
# Globals:
|
||||||
|
# HOSTNAME
|
||||||
|
# OS_FLAVOR
|
||||||
|
# DRIVE
|
||||||
|
# DISK_MODEL
|
||||||
|
# SERIAL_NUMBER
|
||||||
|
# SHORT_TEST_MINUTES
|
||||||
|
# SHORT_TEST_SECONDS
|
||||||
|
# EXTENDED_TEST_MINUTES
|
||||||
|
# EXTENDED_TEST_SECONDS
|
||||||
|
# LOG_FILE
|
||||||
|
# BB_File
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
##################################################
|
||||||
|
log_runtime_info() {
|
||||||
|
log_info "Host: ${HOSTNAME}"
|
||||||
|
log_info "OS Flavor: ${OS_FLAVOR}"
|
||||||
|
log_info "Drive: ${DRIVE}"
|
||||||
|
log_info "Drive Model: ${DISK_MODEL}"
|
||||||
|
log_info "Serial Number: ${SERIAL_NUMBER}"
|
||||||
|
log_info "Short test duration: ${SHORT_TEST_MINUTES} minutes"
|
||||||
|
log_info " ${SHORT_TEST_SECONDS} seconds"
|
||||||
|
log_info "Extended test duration: ${EXTENDED_TEST_MINUTES} minutes"
|
||||||
|
log_info " ${EXTENDED_TEST_SECONDS} seconds"
|
||||||
|
log_info "Log file: ${LOG_FILE}"
|
||||||
|
log_info "Bad blocks file: ${BB_File}"
|
||||||
|
}
|
||||||
|
|
||||||
##################################################
|
##################################################
|
||||||
# Poll repeatedly whether SMART self-test has completed.
|
# Poll repeatedly whether SMART self-test has completed.
|
||||||
# Globals:
|
# Globals:
|
||||||
@@ -439,54 +509,43 @@ run_badblocks_test()
|
|||||||
log_info "Finished badblocks test"
|
log_info "Finished badblocks test"
|
||||||
}
|
}
|
||||||
|
|
||||||
################################################################################
|
##################################################
|
||||||
# ACTIONS BEGINS HERE
|
# Log extensive SMART and non-SMART drive information.
|
||||||
################################################################################
|
# Globals:
|
||||||
|
# DRIVE
|
||||||
|
# LOG_FILE
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
##################################################
|
||||||
|
log_full_device_info() {
|
||||||
|
log_header "SMART and non-SMART information"
|
||||||
|
smartctl --xall --vendorattribute=7,hex48 "${DRIVE}" | tee -a "${LOG_FILE}"
|
||||||
|
}
|
||||||
|
|
||||||
# Create log directory if it doesn't exist
|
##################################################
|
||||||
mkdir -p -- "${LOG_DIR}" || exit 2
|
# Main function of script.
|
||||||
|
# Globals:
|
||||||
|
# SHORT_TEST_SECONDS
|
||||||
|
# EXTENDED_TEST_SECONDS
|
||||||
|
# Arguments:
|
||||||
|
# None
|
||||||
|
##################################################
|
||||||
|
main() {
|
||||||
|
init_log
|
||||||
|
log_header "Started burn-in"
|
||||||
|
|
||||||
if [ -e "${LOG_FILE}" ]; then
|
log_runtime_info
|
||||||
rm "${LOG_FILE}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
log_header "Started burn-in"
|
# test sequence
|
||||||
|
run_smart_test "short" "${SHORT_TEST_SECONDS}"
|
||||||
|
run_badblocks_test
|
||||||
|
run_smart_test "long" "${EXTENDED_TEST_SECONDS}"
|
||||||
|
|
||||||
log_info "Host: ${HOSTNAME}"
|
log_full_device_info
|
||||||
log_info "OS Flavor: ${OS_FLAVOR}"
|
|
||||||
log_info "Drive: ${DRIVE}"
|
|
||||||
log_info "Drive Model: ${DISK_MODEL}"
|
|
||||||
log_info "Serial Number: ${SERIAL_NUMBER}"
|
|
||||||
log_info "Short test duration: ${SHORT_TEST_MINUTES} minutes / ${SHORT_TEST_SECONDS} seconds"
|
|
||||||
log_info "Extended test duration: ${EXTENDED_TEST_MINUTES} minutes / ${EXTENDED_TEST_SECONDS} seconds"
|
|
||||||
log_info "Log file: ${LOG_FILE}"
|
|
||||||
log_info "Bad blocks file: ${BB_File}"
|
|
||||||
|
|
||||||
# Run the test sequence:
|
log_header "Finished burn-in"
|
||||||
run_smart_test "short" "${SHORT_TEST_SECONDS}"
|
cleanup_log
|
||||||
run_badblocks_test
|
}
|
||||||
run_smart_test "long" "${EXTENDED_TEST_SECONDS}"
|
|
||||||
|
|
||||||
# Emit full device information to log:
|
# Entrypoint
|
||||||
log_header "SMART and non-SMART information"
|
main
|
||||||
smartctl --xall --vendorattribute=7,hex48 "${DRIVE}" | tee -a "${LOG_FILE}"
|
|
||||||
|
|
||||||
log_header "Finished burn-in"
|
|
||||||
|
|
||||||
# Clean up the log file:
|
|
||||||
|
|
||||||
if [ "${OS_FLAVOR}" = "Linux" ]; then
|
|
||||||
sed -i -e '/Copyright/d' "${LOG_FILE}"
|
|
||||||
sed -i -e '/=== START OF READ/d' "${LOG_FILE}"
|
|
||||||
sed -i -e '/SMART Attributes Data/d' "${LOG_FILE}"
|
|
||||||
sed -i -e '/Vendor Specific SMART/d' "${LOG_FILE}"
|
|
||||||
sed -i -e '/SMART Error Log Version/d' "${LOG_FILE}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ "${OS_FLAVOR}" = "FreeBSD" ]; then
|
|
||||||
sed -i '' -e '/Copyright/d' "${LOG_FILE}"
|
|
||||||
sed -i '' -e '/=== START OF READ/d' "${LOG_FILE}"
|
|
||||||
sed -i '' -e '/SMART Attributes Data/d' "${LOG_FILE}"
|
|
||||||
sed -i '' -e '/Vendor Specific SMART/d' "${LOG_FILE}"
|
|
||||||
sed -i '' -e '/SMART Error Log Version/d' "${LOG_FILE}"
|
|
||||||
fi
|
|
||||||
|
|||||||
Reference in New Issue
Block a user