Recording command input by the user to generate different files and different user time segments

vim /etc/profile

##### history
USER_IP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
HISTDIR=/usr/share/.history
if [ -z "$USER_IP" ]
then
  USER_IP=`hostname`
fi
if [ ! -d $HISTDIR ]
then
   mkdir -p $HISTDIR
   chmod 777 $HISTDIR
fi
if [ ! -d $HISTDIR/${LOGNAME} ]
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}.history.$DT"
export HISTTIMEFORMAT="[%Y.%m.%d %H:%M:%S]"
export PROMPT_COMMAND='{ date "+%Y-%m-%d %T - USER:$USER IP:$SSH_CLIENT PS:$SSH_TTY - $(history 1 | { read x cmd; echo "$cmd"; })"; } >> $HISTFILE'
chmod 600 $HISTDIR/${LOGNAME}/*.history* 2>/dev/null
TMOUT=600

Output Display

Recording command input by the user to generate different files and different user time segments

Guess you like

Origin blog.51cto.com/9025736/2424827