Skip to content

Instantly share code, notes, and snippets.

@boombatower
Created February 8, 2019 22:27
Show Gist options
  • Save boombatower/810ae6fbdf8649edac6ca040e272b9e5 to your computer and use it in GitHub Desktop.
Save boombatower/810ae6fbdf8649edac6ca040e272b9e5 to your computer and use it in GitHub Desktop.
Wrapper script for smartctl to correct S.M.A.R.T. attribute values for Seagate drives.
#!/bin/bash
# Correct S.M.A.R.T. attribute values for Seagate drives
# https://serverfault.com/questions/313649/how-to-interpret-this-smartctl-smartmon-data
meta_value()
{
echo "$1" | grep -oP ":\s+\K.*"
}
correct_value()
{
if [ $correct -eq 1 ] ; then
echo -n "$(echo "$1" | grep -oP "(\s+\S+){7}\s+")"
echo "$(("$(echo "$1" | grep -oP "(\s+\S+){7}\s+\K\d+")" >> 32))"
else
echo "$1"
fi
}
IFS=$'\n'
output=($(smartctl $@))
correct=0
for line in ${output[@]} ; do
case "$line" in
*"Model Family"*)
if [[ "$(meta_value "$line")" == *"Seagate"* ]] ; then
correct=1
fi
echo "$line"
;;
*Raw_Read_Error_Rate*)
correct_value "$line"
;;
*Seek_Error_Rate*)
correct_value "$line"
;;
*)
echo $line
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment