修改/etc/profile 的配置
写入配置
# wxg 2020 set history audit
export PS1='[\u@\h \W]\$ '
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 /var/log/history ]
then
mkdir /var/log/history
chmod 777 /var/log/history
fi
if [ ! -d /var/log/history/${LOGNAME} ]
then
mkdir /var/log/history/${LOGNAME}
chmod 300 /var/log/history/${LOGNAME}
fi
export HISTSIZE=100000
DT=$(date +"%Y%m%d_%H%M%S")
export HISTFILE="/var/log/history/${LOGNAME}/${USER_IP}_history.$DT"
export HISTTIMEFORMAT="%F %T `whoami` "
方法二
export HISTFILESIZE=99999999
if [ `who am i| awk '{print $NF}'|awk -F'(' '{print NF}'` -eq 2 ];then
unset HISTTIMEFORMAT
export HISTTIMEFORMAT="%F %T-`whoami` `who am i| awk '{print $NF}'` "
else
unset HISTTIMEFORMAT
export HISTTIMEFORMAT="%F %T-`whoami` `hostname` "
Fi