將如下腳本下入到/etc/profile,完了重啓服務器。服務器
history ip=`who -u am i 2>/dev/null| awk '{print $NF}'|sed -e 's/[()]//g'` date=`date +%Y%m%d%H%M%S` if [ "$ip" = "" ];then ip=`hostname` fi if [ ! -d /tmp/history ];then /bin/mkdir -p /tmp/history >>/dev/null 2>&1 /bin/chmod 777 /tmp/history >>/dev/null 2>&1 /bin/chattr +a /tmp/history >>/dev/null 2>&1 fi if [ ! -d /tmp/history/${LOGNAME} ];then /bin/mkdir -p /tmp/history/${LOGNAME} >>/dev/null 2>&1 /bin/chmod 300 /tmp/history/${LOGNAME} >>/dev/null 2>&1 /bin/chattr +a /tmp/history/${LOGNAME} >>/dev/null 2>&1 fi export HISTSIZE=4096 export HISTFILE="/tmp/history/${LOGNAME}/${ip}_history.$date" /bin/chattr +a /tmp/history/${LOGNAME}/* >>/dev/null 2>&1 chmod 600 /tmp/history/${LOGNAME}/*history* >>/dev/null 2>&1