#!/bin/bash #First let's determine the device if [ $# -gt 0 ]; then if [ -b $1 ]; then DRIVE=$1 else echo "$1 is not a block device? Try running fdisk -l for a list of drives" fi else #Try hda? if [ -b /dev/hda ]; then DRIVE=/dev/hda elif [ -b /dev/sda ]; then DRIVE=/dev/sda else echo Could not autofind a drive to work with. Try designating one: smarttest /dev/sdc exit fi fi #echo "Turning on smart" smartctl -s on $DRIVE >/dev/null 2>&1 #if [ $? -ne 0 ]; then # echo Turning SMART on the drive failed for some reason # exit #fi #echo "Running Quick Test" #smartctl --test short $DRIVE >/dev/null 2>&1 #sleep 2m HOURS=`smartctl -d ata -a $DRIVE | grep "Power_On_Hours" | tr " " "\n" | tail -n 1` if [ "$HOURS" == "" ]; then HOURS=`smartctl -d ata -a $DRIVE | grep "# 1" | cut -c 64-75` fi SERIALNUMBER=`smartctl -d ata -a $DRIVE | grep "Serial" | head -n 1 | awk '{print $3}'` ERRORCOUNT=`smartctl -d ata -a $DRIVE | grep "Error" | grep "occurred" | head -n 1 | cut -f 2 -d " "` ERRORTIME=`smartctl -d ata -a $DRIVE | grep "Error" | grep "occurred" | head -n 1 | cut -f 8 -d " "` if [ "$ERRORCOUNT" = "" ] ; then ERRORCOUNT=0 ERRORTIME=0 fi REALLOCATEDSECTORS=`smartctl -d ata -a $DRIVE | grep "Reallocated_Sector" | tr " " "\n" | tail -n 1` SPEED=`hdparm -t $DRIVE | tr " " "\n" | tail -n 2 | head -n 1 | cut -f 1 -d .` PENDINGSECTORS=`smartctl -d ata -a $DRIVE | grep "Current_Pending_Sector" | tr " " "\n" | tail -n 1` echo -e "\033[1;42;37mTest Complete\033[0m" echo "Serial No: $SERIALNUMBER" echo "`date +%D` $DRIVE:" echo "Hours: $HOURS " echo -n "SMART Errors: $ERRORCOUNT" if [ $ERRORCOUNT -gt 0 ]; then let WHENITHAPPEND=$HOURS-$ERRORTIME echo "(last $WHENITHAPPEND hours ago)" else echo fi echo "Reallocated / Pending : $REALLOCATEDSECTORS / $PENDINGSECTORS" echo "Read Speed: $SPEED MB/s" echo echo if [ $HOURS -ge 20000 ]; then echo -e '\033[5;1;37;41mWARNING:\033[0m This drive has over 20,000 hours on it and should not be used as a Primary' fi if [ $ERRORCOUNT -gt 0 ]; then echo -e "\033[5;1;37;41mWARNING:\033[0m The last smart error was $WHENITHAPPEND hours ago, use your judgement to tell if this is relevant (use smartctl -a $DRIVE for more info)" fi if [ $REALLOCATEDSECTORS -gt 0 ]; then echo -e '\033[5;1;37;41mWARNING:\033[0m This drive has some reallocated sectors, this should not be used as a primary and requires judgement if it is to be used for a secondary' fi if [ $PENDINGSECTORS -gt 0 ]; then echo -e '\033[5;1;37;41mWARNING:\033[0m This drive has some pending sectors, this shouldn not be used as a primary and requires judgement if it is to be used for a secondary' fi if [ $SPEED -le 25 ]; then echo -e "\033[5;1;37;41mWARNING:\033[0m This drive is only reading at $SPEED MB/s, which seems slow, is this drive ok and is it on a good motherboard and ide cable?" fi