1. 修改 /etc/profile,profile 文件最后面添加 如下:
# PS1="`whoami`@`hostname`:"'[$PWD]'
history
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 /tmp/dbasky ]
then
mkdir /tmp/dbasky
chmod 777 /tmp/dbasky
fi
if [ ! -d /tmp/dbasky/${LOGNAME} ]
then
mkdir /tmp/dbasky/${LOGNAME}
chmod 300 /tmp/dbasky/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date "+%Y%m%d_%H%M%S"`
export HISTFILE="/tmp/dbasky/${LOGNAME}/${USER_IP} dbasky.$DT"
chmod 600 /tmp/dbasky/${LOGNAME}/*dbasky* 2>/dev/null
2.source /etc/profile
3.进入到/tmp/dbasky/下面,可以看到如下信息:
-rw------- 1 root root 467 Nov 19 13:31 192.168.1.101 RecordLoginInfo.
-rw------- 1 root root 135 Nov 19 13:37 192.168.1.101 RecordLoginInfo.20141119_133633
具体看某一条的登录信息
#cat 192.168.1.101 RecordLoginInfo.20141119_133633