在/etc/profile 追加
export HISTORY_FILE=/var/log/history/userhistory.log readonly PROMPT_COMMAND=‘{ date "+%y-%m-%d %T ##### $(who am i |awk "{print \$1\" \"\$2\" \"\$NF}") #### $(id|awk "{print \$1}") #### $(history 1 | { read x cmd; echo "$cmd";})"; } >>$HISTORY_FILE‘
重读 source /etc/profile即可生效.
mkdir -p /var/log/history/
touch /var/log/history/userhistory.log
在/etc/logrotate.d/新增配置文件 userhistory
/etc/loratate.d/userhistory 内容如下
/var/log/history/userhistory.log { weekly notifempty prerotate /usr/bin/chattr -a /var/log/history/userhistory.log endscript postrotate /bin/chmod 002 /var/log/history/userhistory.log /usr/bin/chattr +a /var/log/history/userhistory.log endscript }
本文出自 “牛磊的博客” 博客,请务必保留此出处http://helloeveryone.blog.51cto.com/6171143/1529723
实时监控Linux服务器用户操作命令,布布扣,bubuko.com
原文地址:http://helloeveryone.blog.51cto.com/6171143/1529723