history
MONFILESAVEPATH=/tmp/usermon <---需要保存的目錄
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 ${MONFILESAVEPATH} ]
then
mkdir ${MONFILESAVEPATH}
chmod 777 ${MONFILESAVEPATH}
fi
if [ ! -d ${MONFILESAVEPATH}/${LOGNAME} ]
then
mkdir ${MONFILESAVEPATH}/${LOGNAME}
chmod -R 300 ${MONFILESAVEPATH}/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date +"%Y%m%d_%H%M%S"`
export HISTFILE="${MONFILESAVEPATH}/${LOGNAME}/${USER_IP}.usrmon.$DT"
chmod -R 600 ${MONFILESAVEPATH}/${LOGNAME}/*usrmon* 2>/dev/null
#cd
#cat /dev/null > .bash_history
保存後需要source才能立即生效,也可退出後再登錄也可生效。