#!/bin/bash"Features" of the script above:
SEVERITIES="err,alert,emerg,crit" WHITELIST="microcode: |\ Firmware Bug|\ i8042: No controller|\ Odd, counter constraints enabled but no core perfctrs detected|\ Failed to access perfctr msr|\ echo 0 > /proc/sys"
# Check for critical dmesg lines from this day date=$(date "+%a %b %e") output=$(dmesg -T -l "$SEVERITIES" | egrep -v "$WHITELIST" | grep "$date" | tail -5)
if [ "$output" == "" ]; then echo "All is fine." exit 0 fi
echo "$output" | xargs exit 1
- It gives you the 5 most recent messages from today
- It allows to whitelist common but useless errors in $WHITELIST
- It uses "dmesg" to work when you already have disk I/O errors and to be faster than syslog parsing
Another good thing about the check is detecting OOM kills or fast spawning of processes.