1、添加下面内容到/etc/bashrc
HISTDIR='/var/log/command.log' if [ ! -f $HISTDIR ];then touch $HISTDIR chmod 666 $HISTDIR fi export HISTTIMEFORMAT="{"TIME":"%F %T","HOSTIP":"$(/usr/sbin/ifconfig |grep 10.0.*.* |grep "inet " |awk -F":" '{print $1}'|awk '{print $2}')","LI":"$(who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g')","LU":"$(who am i|awk '{print $1}')","NU":"$(whoami)","CMD":"" export PROMPT_COMMAND='history 1|tail -1|sed "s/^[ ]+[0-9]+ //"|sed "s/$/"}/">> /var/log/command.log'
2、生效
source /etc/bashrc
3、效果