#!/bin/sh

smartquery() {
		smartctl -d ata -a /dev/sd$1 2>&1 \
		| egrep "$PAT" \
		| while read line; do
			echo "sd$1: $line"
		done
}

tempquery() {
		echo -n "sd$1: "
		hddtemp -nq /dev/sd$1
}

DISKS="a b c d e f g h"
PAT="UDMA_CRC_Error_Count|Reallocated_Event_Count|Offline_Uncorrectable"
PAT="$PAT|Current_Pending_Sector|Raw_Read_Error_Rate|Seek_Error_Rate"

echo "querying... "
for i in $DISKS; do smartquery $i; done | grep -v " 0$" | sort
echo
echo "temperatures... "
for i in $DISKS; do tempquery $i; done | sort -rnk2
