http://bash.cyberciti.biz/monitoring/mcelog-shell-script-to-send-email-alert/
#!/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
本文介绍了一款用于Linux系统的Shell脚本,该脚本能够通过读取/var/log/mcelog文件来收集硬件错误,并在发现错误时通过电子邮件发送警告通知。此脚本适用于预测和快速响应硬件故障。
13万+

被折叠的 条评论
为什么被折叠?



