2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ログメッセージ監視シェル

Last updated at Posted at 2020-08-20

メッセージ監視シェル

メッセージ監視シェルのメモを残す
1.シェル作成
2.systemd登録

1.シェル作成

log-monitor.sh
#!/bin/bash
########################################################
# ログメッセージ監視シェル
#
########################################################
#--- 共通設定 ------------------------------
HOME=`dirname $0`
CONF=${HOME}/_conf
SHELLNAME=`basename $0`

#--- 変数初期値代入 ------------------------
MONITOR_FILE=/var/log/messages
RESULT_FILE=/var/log/messages.result
MATCH_FILE=${CONF}/match.list
EXCLUSTION_FILE=${CONF}/exclustion.list

#--- 内部関数定義 --------------------------
_CHECK_ACTION () {
while IFS= read -r LINE
do
  egrep -f ${MATCH_FILE} <(echo "${LINE}") \
   | egrep -vf ${EXCLUSTION_FILE} >> ${RESULT_FILE}
done
}

#--- メイン処理 ---------------------------
# メッセージ監視処理
tail -n 0 -F ${MONITOR_FILE} | _CHECK_ACTION

exit

2.systemd登録

/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
2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?