Get your drive info
22 Apr 2016
1 minute read

Since two weeks my server is reporting some S.M.A.R.T-errors on one of my hard drives. For a quick overview about all drives (serial numbers, mode) and finding the one which has to been replaced, I’ve written a small script. The script produces a fancy list of all available drives on your Linux host. It uses hdparm in combination with sed for retrieving the drive information, so both are the only dependencies. With a few changes it could be used directly for generating content as Markdown.

DEVICE SERIALNO MODEL
/dev/sda WD-WMAZA5927357 WDC WD20EURS-63S48Y0
/dev/sdb WD-WCAYY0133809 WDC WD20EARS-00J2GB0
/dev/sdc WD-WCAYY0136723 WDC WD20EARS-00J2GB0
/dev/sdd 000000001221090B8B09 M4-CT128M4SSD2
/dev/sde WD-WCAYY0136514 WDC WD20EARS-00J2GB0
/dev/sdf WD-WCAYY0136732 WDC WD20EARS-00J2GB0
/dev/sdg WD-WCAZAA410704 WDC WD20EARS-00MVWB0
#!/usr/bin/env bash
printf "%.0s-" {1..58}
printf "\n"
printf "| DEVICE%2s | SERIALNO%12s | MODEL%15s |\n"
printf "%.0s-" {1..58}
printf "\n"
for i in $( ls /dev/sd* ); do
	if [[ $i =~ ^[A-Za-z_//]+$ ]]; then
		SERNO=$(hdparm -i $i |grep -i SerialNo |cut -d ',' -f 3 | sed 's/^[ ]*[[:alnum:]]*=//')
		MODEL=$(hdparm -i $i |grep -i Model |cut -d ',' -f 1 | sed 's/^[ ]*[[:alnum:]]*=//')
		printf "| %8s | %20s | %20s |\n" "$i" "$SERNO" "$MODEL"
	fi
done
printf "%.0s-" {1..58}
printf "\n"


comments powered by Disqus