参考别人的博客做的修改:
https://blog.csdn.net/jack0201/article/details/76548147?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-3
一个超级简单的脚本,放到变量环境里
vim /etc/profile
加入以下内容:
#history record
history
RQ=`date "+%Y%m%d"`
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/record ]
then
mkdir /tmp/record
chmod 777 /tmp/record
fi
if [ ! -d /tmp/record/${LOGNAME}/${RQ} ]
then
mkdir -p /tmp/record/${LOGNAME}/${RQ}
chmod 300 /tmp/record/${LOGNAME}/${RQ}
fi
export HISTSIZE=8192
SJ=`date "+%H:%M:%S"`
export HISTFILE="/tmp/record/${LOGNAME}/${RQ}/${USER_IP}@${LOGNAME}.$SJ"
chmod 600 /tmp/record/${LOGNAME}/*record* 2>/dev/null
执行变量
source /etc/profile
然后在/tmp/record目录下就能记录下来.........