Leave a note of the message monitoring shell
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
/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