Log message monitoring shell

Message monitoring shell

Leave a note of the message monitoring shell

    1. Shell creation
  1. systemd registration

1. 1. Shell creation

log-monitor.sh


#!/bin/bash
########################################################
#Log message monitoring shell
#
########################################################
#---Common setting------------------------------
HOME=`dirname $0`
CONF=${HOME}/_conf
SHELLNAME=`basename $0`

#---Variable initial value assignment------------------------
MONITOR_FILE=/var/log/messages
RESULT_FILE=/var/log/messages.result
MATCH_FILE=${CONF}/match.list
EXCLUSTION_FILE=${CONF}/exclustion.list

#---Internal function definition--------------------------
_CHECK_ACTION () {
while IFS= read -r LINE
do
  egrep -f ${MATCH_FILE} <(echo "${LINE}") \
   | egrep -vf ${EXCLUSTION_FILE} >> ${RESULT_FILE}
done
}

#---Main processing---------------------------
#Message monitoring process
tail -n 0 -F ${MONITOR_FILE} | _CHECK_ACTION

exit

2. systemd registration

/etc/systemd/system/log-monitor.service


[Unit]
Description = Log Monitor File:/var/log/tstlog

[Service]
ExecStart = /path/to/file/log-monitor.sh
Restart = always
Type = simple

[Install]
WantedBy = multi-user.target

cmd.result


# systemctl enable log-monitor.service
# systemctl start log-monitor.service

Recommended Posts

Log message monitoring shell
Log monitoring
Log monitoring script
[Linux] Log monitoring
Log message processing on Pepper tablets