举个栗子

马辰龙De技术分享
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

logstash收集bash_history历史命令

Posted on 2017-04-12 22:45  ChenlongMa  阅读(447)  评论(0编辑  收藏  举报

原本使用logstash是无法读取/root/.bash_history的。这里用了一个比较巧妙的方法,将history命令记录在message中,然后再使用logstash来读取。

我们需要在/etc/profile中最后加入一行:

PROMPT_COMMAND='history -a >(tee -a ~/.bash_history | logger -t "$USER[$$] $SSH_CONNECTION  bash_history")'

/var/log/message效果如下

Apr 12 22:43:03 1.1.1.1  root[4719] 2.2.2.2  44496 14.18.237.48 22  bash_history:  cat /etc/profile