centos 记录所有用户操作命令的脚本,


使用history不能看到所有用户的命令记录,如何看所有用户的操作记录。

如下:

在 /etc/profile 最下面加入如下代码即可.

 

PS1="`whoami`@`hostname`:"'[$PWD]'
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 /tmp/historylog ]
then
mkdir /tmp/historylog
chmod 777 /tmp/historylog
fi
if [ ! -d /tmp/historylog/${LOGNAME} ]
then
mkdir /tmp/historylog/${LOGNAME}
chmod 300 /tmp/historylog/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date "+%Y-%m-%d_%H:%M:%S"`
export HISTFILE="/tmp/historylog/${LOGNAME}/${USER_IP} log.$DT"
chmod 600 /tmp/historylog/${LOGNAME}/*dbasky* 2>/dev/null

  

运行下面命令让脚本立即生效
source /etc/profile

记录文件在 /tmp/historylog/

 

相关内容

    暂无相关文章