mcelog: Shell Script To Send Email Alert When Hardware Errors Detected

#!/bin/bash
# Linux 64 bit kernel shell script to collect hardware errors via /var/log/mcelog
# and send email alert.
# -------------------------------------------------------------------------
# Copyright (c) 2008 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# Tested under RHEL and Debian Linux 64 bit version.
# mcelog must be installed.
# See: http://www.cyberciti.biz/tips/linux-server-predicting-hardware-failure.html
LOGGER=/usr/bin/logger
FILE=/var/log/mcelog
AEMAIL="vivek@nixcraft.net.in"
ASUB="H/W Error - $(hostname)"
AMESS="Warning - Hardware errors found on $(hostname) @ $(date). See log file for the details /var/log/mcelog."
OK_MESS="$0 - OK: NO Hardware Error Found."
WARN_MESS="$0 - ERROR: Hardware Error Found."
 
die(){
	echo "$@"
	exit 999
}
 
warn(){
	echo $AMESS | email -s "${ASUB}" ${AEMAIL}
	$LOGGER "$WARN_MESS"
}
 
[ ! -f "$FILE" ] && die "Error - No $FILE exists or mcelog is not configured"
[ $(grep -c -i "hardware error" $FILE) -gt 0 ] && warn || $LOGGER $OK_MESS

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our email newsletter to make sure you don't miss a single tip/tricks.

{ 5 comments… read them below or add one }

1 Mehdi August 14, 2009 at 10:36 am

Thanks, I’ll edit and use it…(heh I dont think you want to get emails for my hardware failure) :-)

Regards;

Reply

2 Mehdi August 14, 2009 at 10:43 am

Vivek;

I tried the script on my ubuntu904 (i386 machine) but I get this error;
(I apt-get install mcelog ) but still get;
Error – No /var/log/mcelog exists or mcelog is not configured

How do I configure the mcelog?

Thanks!

Reply

3 Vivek Gite August 14, 2009 at 10:54 am

This script only works with 64bit Linux kernel.

Reply

4 vamsi November 19, 2009 at 4:34 am

can you please tell how to get this work on 32 bit os ?

Thanks :)

Reply

5 Vivek Gite November 20, 2009 at 6:08 pm

No, you can’t this only work in 64bit CPU / computer.

Reply

Previous post:

Next post: