`

linux操作命令实时传显示在kibana

阅读更多

 

 刚开始想到history ,history有三个不足的地方:

        (1)用户exit,history才有记录

        (2)history -c 有被动删除风险

        (3)不够实时

 

history这方案,kill掉,再想/etc/profile。profile,用户登录先检查的文件,并且里面可以写shell。具体shell如下: 

 

USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`

if [ "$USER_IP" = "" ]

then

USER_IP=`hostname`

fi

if [ ! -d /XX ]

then

mkdir -p /XX

chown -R admin:admin /XX

chmod -R 771 /XX

fi

if [ ! -f /XX/records.log ];then

touch /XX/records.log

chmod -R 777 /XX/records.log

fi

export PROMPT_COMMAND='{ date "+%Y-%m-%d %T ${USER_IP} $(who am i |awk "{print \$1\" \"\$2"})  $(history 1 | { read x cmd; echo "$cmd"; })"; } >> /XX/records.log'

 

      

把各种用户的操作命令记录到本地,再到kibana展示。

 



 

 

  • 大小: 19.2 KB
0
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics