scripts/smart.run.test.sh

47 lines
1.2 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/sh
# .. vim: foldmarker=[[[,]]]:foldmethod=marker
# This script will try to run a smart test on all compatible devices.
# The test can be passed as first argument.
# Vars [[[
debug="0"
## Colors [[[
c_redb='\033[1;31m'
c_magentab='\033[1;35m'
c_reset='\033[0m'
## ]]]
temp_dir=$(mktemp -d -t smart.run.test-XXXXXX.tmp)
smart_device_list="${temp_dir}/smart.device.list"
# ]]]
# Create files
true > "${smart_device_list}"
# Get the list of all available devices
smartctl --scan >> "${smart_device_list}"
if test -s "${smart_device_list}"; then
while IFS= read -r LINE; do
## Get device path
scanned_disk=$(echo "${LINE}" | cut -d" " -f1)
## Try to determine the best type
scanned_type=$(echo "${LINE}" | cut -d" " -f3)
[ "${debug}" -eq "0" ] && printf "${c_magentab}%-6b${c_reset}\n" "DEBUG: smartctl scan ${scanned_disk} with type ${scanned_type}."
done < "${smart_device_list}"
# If the file is empty
else
printf "${c_redb}%-6b${c_reset}\n" "ERROR: The device list looks empty, check ${smart_device_list} file and \`smartctl --scan\` command."
exit 1
fi
# Remove temp_dir if debug is disable
[ "${debug}" -eq "0" ] || rm -rf -- "${temp_dir}"
exit 0