Send email on SMART errors in Windows and Linux.


When smart values change or a drive is about to fail you want to know beforehand, before an actual SMART error prevents you from rescuing data. This script logs the SMART values of your drives. If any important value changes it will send an email. So if you suddenly get an email every week where one smart value changes you know early enough that this drive will die. It will keep a log of every time something changed in a smart_realloc_count.<date> file.
The Windows SMARTcheck script itself. Linux users get Linux smartcheck.
The linux version is pretty straightforward and was there first, and includes an mdstat check for my software RAID. If you can do linux, you don't need extra information *g*. Get SendEmail, edit
 HARDDRIVES 
and
 SENDEMAILCOMMAND 
, set up a cron job and/or init task and done.
The Windows version requires a bit more work. My solution is based on SMARTMonTools, you need them. It requires SED and GREP from UnixUtil and SendEmail for sending alarm mails.

The approach: Read the smart value of each drive. Compare with the previously recorded value. If there is a difference send alarm.

The Setup: Install Smartmontools, wherever you want them.
copy GREP.EXE and SENDEMAIL.EXE from UnixTools and SendEmail to the main installation folder, not the subdirectory /bin.
copy SMARTcheck.cmd to the main installation folder.
EDIT the SMARTcheck.cmd script. You will have to fill (or correct):
PROGDIR 
to where your smartmon tools are installed. Usually C:\Program Files\smartmontools.
LOGFILE 
to what you want to name to logfile. You have to keep the trailing dot.
DRIVES 
here you have to enter all your HDD and SSD drives by their LINUX names /dev/sda, /dev/sdb and so on. Count the number of drives you have, and add as many as you have.

set PROGDIR=C:\prog\smartmontools
set LOGFILE=smart_realloc_count.
set DRIVES=/dev/sda /dev/sdb /dev/sdc /dev/sdd /dev/sde

and don't forget the SendEmail command at the end!

"%PROGDIR%\sendemail-v1.56.exe" -f (senderemailadress) -t (recipientemailaddress) -s (smtp-mailserver) -xu (smtp-username) -xp (smtp-password) -o tls=no -u "%COMPUTERNAME% %CURRENTDATE% SMART Status, Reallocated Sector Count" < "%LOGFILE%%CURRENTDATE%"

And as last task: Create a scheduled task to call this program regularly. I'd recommend two triggers: One is 15 minutes after booting, and the other is weekly or daily at a time when your machine is running.

What it does in short: Reads the SMART values, but not all, just selected values. Sorts the result by drive serial number since windows tends to mix up the drive order during every reboot. This result is then logged, and if there is a difference between the previous log and the current copy the log to a file name with the date attached and send an email. If an email could not be sent add "could not send" to the last log file to force a retry on the next run, it will retry until the email was sent.

Legal Stuff: This is a private homepage. All "TM" mentioned here belong to their owners and not me. Anyone offended contact me at email-address.