mirror of
https://github.com/jimeh/dotfiles.git
synced 2026-02-19 10:46:40 +00:00
Add smart-health-check
This commit is contained in:
59
bin/smart-health-check
Executable file
59
bin/smart-health-check
Executable file
@@ -0,0 +1,59 @@
|
||||
#! /usr/bin/env bash
|
||||
|
||||
if [ -z $1 ]; then
|
||||
echo "usage: smart-health-check <device>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
trim() {
|
||||
local string="$@"
|
||||
string="${string#"${string%%[![:space:]]*}"}"
|
||||
string="${string%"${string##*[![:space:]]}"}"
|
||||
echo -n "$string"
|
||||
}
|
||||
|
||||
check-status() {
|
||||
local raw_status="$(smartctl -H $1)"
|
||||
local status="$(echo "$raw_status" | grep "^SMART overall-health")"
|
||||
|
||||
if [[ "$(trim "$status")" != *"PASSED" ]]; then
|
||||
echo "$(tput setaf 1)SMART Status: FAIL:$(tput sgr0)" \
|
||||
"smartctl -H $1:"
|
||||
echo ""
|
||||
echo "$raw_status"
|
||||
exit 3
|
||||
fi
|
||||
}
|
||||
|
||||
check-attributes() {
|
||||
local attr
|
||||
local fail=0
|
||||
local raw_status="$(smartctl -A $1)"
|
||||
local report="$(echo "$raw_status" | grep "^ID# ")"
|
||||
|
||||
for id in 1 5 10 196 198; do
|
||||
attr="$(echo "$raw_status" | grep "^\s*${id}\s")"
|
||||
if [ -n "$(trim "$attr")" ] && [[ "$(trim "$attr")" != *" 0" ]]; then
|
||||
fail=1
|
||||
report="$report\n$attr"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ $fail != 0 ]; then
|
||||
echo "$(tput setaf 2)SMART Status: PASSED:$(tput sgr0)" \
|
||||
"$(tput setaf 1)- may FAIL soon:$(tput sgr0)" \
|
||||
"smartctl -A $1:"
|
||||
echo ""
|
||||
echo -e "$report"
|
||||
exit 2
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
check-status $1
|
||||
check-attributes $1
|
||||
echo "SMART Status: $(tput setaf 2)PASSED$(tput sgr0)"
|
||||
}
|
||||
|
||||
|
||||
main $@
|
||||
Reference in New Issue
Block a user