What SMART Stats Tell Us About Hard Drives
Ten years ago when I was I trying to learn how to "program", I wrote this bash script (to be added into /etc/cron.daily) that dumps a few smart stats that are normally 0 or slow changing, diffs it with the copy from the previous run, and if anything is different (and cron in configured right) it will email you the diff. Every linux machine I touch gets this file dropped onto it. I've replaced many hard drives because of it<p><pre><code>    #!/bin/bash
    
    
    smartctl -a /dev/sda > /root/smartStates
    grep Reallocated_Sector_Ct /root/smartStates > /root/stats
    grep Current_Pending_Sector /root/smartStates >> /root/stats
    grep Offline_Uncorrectable /root/smartStates >> /root/stats
    grep UDMA_CRC_Error_Count /root/smartStates >> /root/stats
    
    touch /root/statsOld
    cmp /root/stats /root/statsOld
    result=$?
    
    if [[ $result -ne "1" && $result -ne "0" ]]
      then
    	echo "Something went wrong"
    	exit -1
    fi
    
    if [[ $result -eq "1" ]]
      then
    	echo "Files are different\n"
    	cat /root/stats
    fi
    
    mv /root/stats /root/statsOld
    rm /root/smartStates</code></pre>