vim /etc/profile
在未行加入

export PROMPT_COMMAND='{ date "+[ %Y%m%d %H:%M:%S `whoami` ] `history 1 | { read x cmd; echo "$cmd  from ip:$SSH_CLIENT   $SSH_TTY";
}`"; }>> /home/login.log'

source /etc/profile 生效


========================================================================
vim /etc/profile
在未行加入

RMIP=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'`
TIME=`date +%Y%m%d.%H:%M.%S`
LOGS="/tmp/.hist/$TIME.$USER.hist"
HOST=`/bin/hostname`

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

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

script -q $LOGS && mail -s "$TIME, $USER FROM $RMIP LOGIN $HOST" user@domain.com < $LOGS && rm -f $LOGS