alantop

使用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/

 

分类:

技术点:

相关文章:

  • 2021-11-28
  • 2022-12-23
  • 2022-12-23
  • 2021-05-07
  • 2021-04-01
  • 2022-01-11
  • 2021-09-23
  • 2021-12-10
猜你喜欢
  • 2022-01-16
  • 2022-01-20
  • 2022-12-23
  • 2021-06-10
  • 2021-10-26
  • 2021-07-12
  • 2022-12-23
相关资源
相似解决方案