Article 5RT7Y Bash scripting for hard drive testing

Bash scripting for hard drive testing

by
URT-Tech
from LinuxQuestions.org on (#5RT7Y)
Hello everyone,

Apologies if this is in the wrong forum, this seems to be the most correct one as I am a bit of a newbie to linux.

I work for a company that wipes and resells used hard drives and we use a script in linux to test drives with smartctl and hdparm before we wipe them in our software.

I'm trying to update our scripts to be faster and easier so that almost anyone regardless of knowledge level can test hard drives. The script I've updated works exactly the way I want it to, but I'm trying to make it easier to notice when a drive has failed the test. Here's the current script:

Code:red=`tput setaf 1`
green=`tput setaf 2`
blue=`tput setaf 6`
reset=`tput sgr0`

clear
echo '------------------------------------------------------'

for OUTPUT in $(lsscsi | grep ATA)
do
if [[ $OUTPUT = /dev/* ]]
then
hdparm --security-set-pass password $OUTPUT &> /dev/null
hdparm --security-unlock password $OUTPUT &> /dev/null
hdparm --security-disable password $OUTPUT &> /dev/null
smartctl -a $OUTPUT | egrep 'Model: |Serial |Reallocated_S|Curr|does|Power_O'
hdparm -I $OUTPUT | egrep 'locked|enabled'
echo '------------------------------------------------------'
fi
done
echo $(lsscsi | grep -c ATA) Drives Found
echo
echo "**********************************************************************************************"
echo
echo "${blue}In order to pass the SMART test a drive's results must match the parameters below:${reset}"
echo
echo "${blue}Reallocated_Sector_Ct${reset} = ${green}0${reset}"
echo "${blue}Current_Pending_Sector${reset} = ${green}0${reset}"
echo "${blue}Power_On_Hours${reset} <= ${green}50,000${reset}"
echo
echo "**********************************************************************************************"Text in red I added to the script.

Here's an example of what the output looks like:

Code:------------------------------------------------------
Device Model: WDC WD5000AAKX-753CA1
Serial Number: WD-WMAYUX086972
5 Reallocated_Sector_Ct 0x0033 200 200 140 Pre-fail Always - 0
9 Power_On_Hours 0x0032 048 048 000 Old_age Always - 38037
197 Current_Pending_Sector 0x0032 200 200 000 Old_age Always - 0
not enabled
not locked
------------------------------------------------------

1 Drives Found

**********************************************************************************************

In order to pass the SMART test a drive's results must match the parameters below:

Reallocated_Sector_Ct = 0
Current_Pending_Sector = 0
Power_On_Hours <= 50,000

**********************************************************************************************What I'm hoping I can do is get it so that when it displays those three SMART attributes I can set it so that the RAW_VALUE will display as red or green as a pass or fail based on our criteria given above. Also if I could get it to show just the name of the SMART attribute and the RAW_VALUE instead of all the extra stuff, that would be great too.

I'm pretty good at being able to copy what someone has already done and tweak it to work the way I want, but when it comes to actually writing something I have no clue. Anybody have any ideas?latest?d=yIl2AUoC8zA latest?i=Ko4ThpSdogw:LFFx9yFgnrg:F7zBnMy latest?i=Ko4ThpSdogw:LFFx9yFgnrg:V_sGLiP latest?d=qj6IDK7rITs latest?i=Ko4ThpSdogw:LFFx9yFgnrg:gIN9vFw
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments