SHIFT

--- Sjoerd Hooft's InFormation Technology ---

User Tools

Site Tools


Sidebar

Recently Changed Pages:

View All Pages


View All Tags


LinkedIn




WIKI Disclaimer: As with most other things on the Internet, the content on this wiki is not supported. It was contributed by me and is published “as is”. It has worked for me, and might work for you.
Also note that any view or statement expressed anywhere on this site are strictly mine and not the opinions or views of my employer.


Pages with comments

View All Comments

scriptlogmessagesreport

Script: Bash: Run Report on Syslog Messages

I've setup my management server as my syslog server as well. All servers sent their warning messages or higher to this server and I've created this script so I receive all unique messages from the last week, on Monday morning in my email to be included in my weekly check.

#!/bin/bash
# This report show all entries in /var/log/messages for the last week,
#    makes them unique and counts the number of messages.
# Then it will mail the report to whoever needs it.
 
# Script Variables
HOSTNAME_SHORT=`hostname -s`
BASEDIR=`dirname $0`
WHATAMI=`basename $0`
DATE=`date +%Y%m%d`
LASTWEEK=`date --d='last Week' +%V`
TOMAIL=sjoerd @ getshifting.com,it department @ getshifting.com
REPORT=/tmp/$WHATAMI.txt
 
# /var/log/messages logfile due to rotation
LASTSUNDAY=`date --d='last Sunday' +%Y%m%d`
LOGFILE=/var/log/messages-$LASTSUNDAY
 
# Start of Script
 
# Clear logfile and make things look nice
echo "This is the messages report log" > $REPORT
echo "Server: $HOSTNAME_SHORT" >> $REPORT
echo "Week number: $LASTWEEK" >> $REPORT
echo " " >> $REPORT
echo "Report messages": >> $REPORT
 
# Get all messages from logfile, sqeeze spaces,
#    remove the date columns and sort and count the logentries
cat $LOGFILE | tr -s ' ' | cut -d' ' --complement -f1-3 | sort | uniq -c >> $REPORT
 
# Mail report
echo "See attachment" | mailx -s "Weekly syslog messages Red Hat Algo environment" -a $REPORT $TOMAIL
 
# End of Script
exit 0

Then schedule it in cron like this:

# Run messages report every monday at 06:00
0 6 * * 1 root /adminscripts/logmessagesreport
You could leave a comment if you were logged in.
scriptlogmessagesreport.txt · Last modified: 2021/09/24 00:25 (external edit)