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