EGOPOLY

Topics include: programming, Apple, Unix, gadgets, large-scale web sites and other nerdy stuff.

DIY SMART disk reporter.

2006-09-19 11:43:12

Most (all?) SATA drives have self-diagnostics that report hardware problems. There are a number of freeware utilities available to monitor your disks for problems via this feature.

Here is a do-it-yourself SMART reporter. First create this script, and name it bin/macmaint or something.

#! /bin/sh
[email protected]
host=`hostname`

diskstatus=`/usr/sbin/diskutil info disk0 | grep SMART | awk '{print $3}'`

#debug
#echo $diskstatus

if test "$diskstatus" == "Verified"; then
    #echo "disk ok"
    /usr/bin/true
else
    #echo "disk very bad"
    /usr/sbin/diskutil info disk0 | mail -s "Disk problem on $host" $email
fi

Next, add it to your crontab, like this.

% crontab -e

05 * * * * bin/macmaint

This will run once/hour, and email if anything goes wrong.