wiki.getshifting.com

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

User Tools

Site Tools


start

SHIFT-WIKI - Sjoerd Hooft's InFormation Technology

This WIKI is my personal documentation blog. Please enjoy it and feel free to reach out through blue sky if you have a question, remark, improvement or observation. See below for the latest additions, or use the search or tags to browse for content.


Bash: Run a Report on Syslog Messages

Summary: How to receive all messages from a syslog server from the last week using a script.
Date: Around 2022
Refactor: 6 April 2025: Checked links and formatting.

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 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

This wiki has been made possible by:

2025/06/01 11:59

HTML: Redirect

Summary: Create a redirect with HTML
Date: Around 2010
Refactor: 4 January 2025: Checked links and formatting.

→ Read more...

2025/06/01 11:59

Bash: Use Full Lines From Inputfile as Matching Pattern

Summary: How to use an inputfile from which the full line is used as a search pattern in other files. The other files all start with SHIFT. The inputfile lines contain whilespaces.
Date: Around 2014
Refactor: 6 April 2025: Checked links and formatting.

inputfile=/tmp/inputfile.txt

nlines=`cat $inputfile | wc -l`
teller=1
while [[ $teller -lt $nlines ]]; do
        match=`head -$teller $inputfile | tail -1`
        grep "$match" SHIFT* > /dev/null
        if [ $? -eq 0 ]; then
                echo $match still exists!
        fi
        teller=$(($teller+1))
done

Explained code:

inputfile=/tmp/inputfile.txt

# Count the number of lines in the inputfile. This is the number of times the loop will be gone through.
nlines=`cat $inputfile | wc -l`
teller=1
while [[ $teller -lt $nlines ]]; do
        # Use head and tail to set a variable with a complete line from the inputfile
        match=`head -$teller $inputfile | tail -1`
        grep "$match" SHIFT* > /dev/null
        if [ $? -eq 0 ]; then
                echo $match still exists!
        fi
        teller=$(($teller+1))
done

This wiki has been made possible by:

2025/06/01 11:59

AIX NIM Client

Summary: ALthough AIX is by now on version 7.3 I find these old pages so fascinating I decided to keep them. On this page I'll show you how to a work with a standalone client to the NIM environment. This page is for AIX 5.3 and AIX 6.1.
Date: Between 2010-2013
Refactor: 21 December 2024: Checked formatting.

→ Read more...

2025/06/01 11:59

<< Newer entries | Older entries >>

This wiki has been made possible by:

start.txt · Last modified: by sjoerd