#!/bin/bash
# This script makes the computer tell you about the errors at boot time.
# It will be executed in the /etc/rc.d/rc.local file at boot time.
# You will need festival package installed or compiled to actually hear it.
# If you don't understand something then just know that everything is there for a purpose :-)
# Written by A. M. Dimitrov

touch /tmp/info
touch /root/result

DATEIND=`date +%b\ %e`
TIMEIND=`date +%k`:

cat /var/log/boot.log|grep -E "$DATEIND"|grep "$TIMEIND"|grep -i "failed"       >> /tmp/info
cat /var/log/boot.log|grep -E "$DATEIND"|grep "$TIMEIND"|grep -i "not"          >> /tmp/info
#cat /var/log/boot.log|grep -E "$DATEIND"|grep "$TIMEIND"|grep -i "no"          >> /tmp/info
cat /var/log/boot.log|grep -E "$DATEIND"|grep "$TIMEIND"|grep -i "unknown"      >> /tmp/info

ERRORSCOUNT=`wc -l /tmp/info | cut -d" " -f7`

echo "Summary for boot time on `date +%A\ %B\ %e` ! at: `date +%r`:" > /root/result

#Normal NO ERRORS
if  [ $ERRORSCOUNT -eq 0 ] ; then
        echo "The Computer Is Up and running!" >> /root/result;
        echo "There were $ERRORSCOUNT errors at boot time!" >> /root/result
        echo "The system is online! All devices seem too be functioning properly!" >> /root/result
        echo "Welcome to Linux! Please login to begin!" >> /root/result
fi

#Bad SOME ERRORS
if   [ $ERRORSCOUNT -gt 0 ] ; then
        echo "System is up!" >> /root/result
        echo "There were $ERRORSCOUNT errors at boot time!" >> /root/result
        echo "The system may or may not be functioning properly!" >> /root/result
        echo "The following errors were found:" >> /root/result
        cat /tmp/info >> /root/result
        echo "! For more information look at your /var/log/boot.log file!" >> /root/result
        echo "Welcome to Linux! Please login to begin!" >> /root/result
fi

festival --tts /root/result
rm /tmp/info /root/result

