centos 7 查看所有登录用户的操作历史
原创
©著作权归作者所有:来自51CTO博客作者杨虎成博客的原创作品,请联系作者获取转载授权,否则将追究法律责任
centos 7 查看所有登录用户的操作历史
文章目录
- 编辑文本
- 在底部写入
- 使它生效
- 查看历史记录/opt/history
编辑文本
在底部写入
#记录每个用户的操作信息
export PS1='[\u@\h \w]# '
history
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 /opt/history ]
then
mkdir /opt/history
chmod 777 /opt/history
fi
if [ ! -d /opt/history/${LOGNAME} ]
then
mkdir /opt/history/${LOGNAME}
chmod 300 /opt/history/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date +"%Y%m%d_%H%M%S"`
export HISTFILE="/opt/history/${LOGNAME}/${USER_IP} history.$DT"
chmod 600 /opt/history/${LOGNAME}/*history* 2>/dev/null
使它生效
查看历史记录/opt/history