Skip to content

Instantly share code, notes, and snippets.

@warpfork
Created July 7, 2016 04:39
Show Gist options
  • Save warpfork/142fcb5b1d1da92bc2adb46ed3cac8e0 to your computer and use it in GitHub Desktop.
Save warpfork/142fcb5b1d1da92bc2adb46ed3cac8e0 to your computer and use it in GitHub Desktop.
wtfdisks -- make smartmon output vaguely readable. maybe.
#!/bin/bash
#
# Turn on smartmon;
# ask it to do a test;
# wait an arbitrary amount of time because smartmon's api is childish;
# ask for failure reports.
#
# Pretty print the whole thing, in as much as possible, because smartmon's output is fugly to the point of impeding usability.
#
color_phase="\033[0;33m"
color_device="\033[0;35m"
color_scream="\033[0;31m"
color_green="\033[0;32m"
color_warn="\033[1;33m"
color_none="\033[0m"
highlight() {
set -euo pipefail
keyword="$1"
color="$2"
sed "$(printf "%b" "s/${keyword}/${color}&${color_none}/")" -
}
realsmart="`which smartctl`"
smartctl() {
"${realsmart}" "$@" \
| sed '/^$/d' \
| sed '/^smartctl 6/d' \
| sed '/^Copyright (C) /d'
}
echo -e "${color_phase}== ===>>${color_none}"
echo -e "${color_phase}== starting all tests =====>>${color_none}"
echo -e "${color_phase}== ===>>${color_none}"
(
for x in /dev/sd? ; do (
echo -e "${color_device}=== $x ===>${color_none}"
(
smartctl -s on --test=long $x
) 2>&1 | sed 's/^/^\t/'
echo -ne "${color_device}==< $x ===${color_none}\n\n\n\n"
); done
) 2>&1 | sed 's/^/^\t/'
sleep 1 ## fuckkit, you can't *actually* guess how long the tests are gonna take. just run it repeatedly until your prayers are answered.
echo -e "${color_phase}== ===>>${color_none}"
echo -e "${color_phase}== report! =====>>${color_none}"
echo -e "${color_phase}== ===>>${color_none}"
(
for x in /dev/sd? ; do (
echo -e "${color_device}=== $x ===>${color_none}"
(
smartctl -i $x | grep -e "^Model Family:" -e "^Device Model:" -e "^Serial Number:" -e "^SATA Version"
smartctl -H $x \
| highlight "FAILED!" "${color_scream}" \
| highlight "PASSED" "${color_green}"
## Note that there are lots of other 'FAILING_NOW' values possible, but some of them are
## for things like air temp which are completely not reasonable to call "failures".
## You can highlight their presense with `| highlight "marginal Attributes" "${color_warn}"` but it's really just not interesting.
) 2>&1 | sed 's/^/^\t/'
echo -ne "${color_device}==< $x ===${color_none}\n\n\n\n"
); done
) 2>&1 | sed 's/^/^\t/'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment