/var/log/messages filling to quickly with junk

Symptom:

The /var/log/messages (through messages.4, by default) are filling too quickly with junk messages

Problem:

Many components will occasionally spam the messages file with cosmetic messages. An example of this is “vrrp_recv: discarded unknown VRID N packet from IP_Address” messages in gaia w/VRRP (ref: sk92605, pre R77.10). There are some other known issues as well You could increase the log file size (ref: sk36798), but this may still miss what you are looking for, especially in very intermittent issues.

Solution:

The script below that will assist . Required!!! Replace <Nth spamming message match string> with a portion of text from the spamming log messages you want to exclude. Without other modification this script creates 99x ~2MB files of all other messages.

To run it, get into expert mode, run
vi purifier.sh

and paste it in (a key to enter edit, first), and save it (:wq keys). Then run:
chmod 555 ./purifier.sh
nohup ./purifier.sh &

The last command starts the script in the background under nohup (no hang up so the user session does not have to keep going).

########Start copy below########
#!/bin/bash

filen=0
if [ ! -d “/var/log/tmp” ]; then
mkdir /var/log/tmp
fi
touch /var/log/tmp/purified_mess_0.log
while read line; do
if ((“$filen” > “99”)); then
break              ## exits while loop if there are more than 99 files (can modify this condition to be less or more)
fi
if ((“$(wc -c /var/log/tmp/purified_mess_$filen.log |  cut -f 1 -d ‘ ‘)” >= “2000000”)); then
let “filen = filen + 1”
touch /var/log/tmp/purified_mess_$filen.log             ## creates next file if the current has more than ~2MB files (can modify this condition to be less or more, wouldn’t suggest making it too big per file)
fi
if [[ “$line” == *”<1st spamming message match string>”* ]]; then
continue
elif [[ “$line” == *”<2nd spamming message match string>”* ]]; then
continue
## Repeat elif for any number of matching expression, before the else. If only 1 message is spamming then don’t use elif
else
echo $line >> /var/log/tmp/purified_mess_$filen.log         ## print purified logs to current log file
fi
done < <(tail -f /var/log/messages)

exit
########Stop copy above########

 

 

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.