#history
export HISTTIMEFORMAT="[%Y.%m.%d %H:%M:%S]"
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
HISTDIR=/var/log/.hist
if [ -z $USER_IP ]
then
USER_IP=`hostname`
fi
export HISTTIMEFORMAT="[%Y.%m.%d %H:%M:%S]"
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
HISTDIR=/var/log/.hist
if [ -z $USER_IP ]
then
USER_IP=`hostname`
fi
if [ ! -d $HISTDIR ]
then
mkdir -p $HISTDIR
chmod 777 $HISTDIR
fi
then
mkdir -p $HISTDIR
chmod 777 $HISTDIR
fi
if [ ! -d $HISTDIR/${LOGNAME} ]
then
mkdir -p $HISTDIR/${LOGNAME}
chmod 300 $HISTDIR/${LOGNAME}
fi
then
mkdir -p $HISTDIR/${LOGNAME}
chmod 300 $HISTDIR/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date +%Y%m%d_%H%M%S`
export HISTFILE="$HISTDIR/${LOGNAME}/${USER_IP}.hist.$DT"
chmod 600 $HISTDIR/${LOGNAME}/*.hist* 2>/dev/null
DT=`date +%Y%m%d_%H%M%S`
export HISTFILE="$HISTDIR/${LOGNAME}/${USER_IP}.hist.$DT"
chmod 600 $HISTDIR/${LOGNAME}/*.hist* 2>/dev/null
得到的结果,永久保存,每个用户的命令记录分目录保存
# ls -l /var/log/.hist/root/
-rw------- 1 root root 546 2006-05-26 10:00 218.82.245.54.hist.20060526_092458
-rw------- 1 root root 243 2006-05-28 13:28 218.82.245.54.hist.20060528_114822
-rw------- 1 root root 10 2006-05-28 12:18 218.82.245.54.hist.20060528_121605
# ls -l /var/log/.hist/root/
-rw------- 1 root root 546 2006-05-26 10:00 218.82.245.54.hist.20060526_092458
-rw------- 1 root root 243 2006-05-28 13:28 218.82.245.54.hist.20060528_114822
-rw------- 1 root root 10 2006-05-28 12:18 218.82.245.54.hist.20060528_121605