把下面的代码粘贴到 /etc/profile文件 后面可以设置HISTFILE变量把登录信息记录到/tmp/.hist/目录下

 

# history
USER_IP=`who am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`

if [ "$USER_IP" = "" ]
then
  USER_IP=`hostname`
fi

if [ ! -d /tmp/.hist ]
then
   mkdir /tmp/.hist
   chmod 777 /tmp/.hist
fi

if [ ! -d /tmp/.hist/${LOGNAME} ]
then
    mkdir /tmp/.hist/${LOGNAME}
    chmod 300 /tmp/.hist/${LOGNAME}
fi
HISTSIZE=4096
export HISTSIZE
DT=`date "+%Y%m%d_%H%M%S"`
export DT
HISTFILE="/tmp/.hist/${LOGNAME}/${USER_IP}.hist.$DT"
export HISTFILE
chmod 600 /tmp/.hist/${LOGNAME}/*.hist* 2>/dev/null
umask 022

Logo

更多推荐