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

syslog (rsyslog) の出力をコマンドに送る

Posted at

最も単純な例。

/usr/local/bin/hoge.sh
echo "# $1 #" >> /var/log/hoge.log

にログを送りたい場合。

/etc/rsyslog.d/hoge.conf
$template sample_templ, "%msg:2:$%"
auth,authpriv.*    ^/usr/local/bin/hoge.sh;sample_tmpl

とすると、/var/log/auth.log に送られる内容が hoge.sh にも送られる。

  • template を使用しないと、最後に改行がつく
  • %msg% の先頭に1文字空白が入っているので、2文字目以降を出している
/var/log/auth.log
Oct 27 22:28:36 EXELION-X1 su: (to ken) root on tty2
Oct 27 22:28:36 EXELION-X1 su: pam_unix(su:session): session opened for user ken by (uid=0)
Oct 27 22:28:36 EXELION-X1 su: pam_unix(su:session): session closed for user ken
/var/log/hoge.sh
# (to ken) root on tty2 #
# pam_unix(su:session): session opened for user ken by (uid=0) #
# pam_unix(su:session): session closed for user ken #

^ を使うより "omlog" を使うほうが今風らしい。
https://www.rsyslog.com/doc/master/configuration/modules/omprog.html

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