Linux服务器在使用过程中,经常会有除自己之外的其他人员使用。并不是每个人都对Linux服务器特别熟悉,难免会有一些操作导致服务器报错。
history
RQ=`date "+%Y%m%d"`
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 /var/log/histories ]
then
mkdir /var/log/histories
chmod 777 /var/log/histories
fi
export HISTSIZE=8192
DT=`date "+%H:%M:%S"`
export HISTFILE="/var/log/histories/history.log"
export PROMPT_COMMAND='{ date "+[%Y-%m-%d %T] ##### $(who am i |awk "{print \$1\" \"\$2\" \"\$5}") #### $(pwd) #### $(history 1 | { read x cmd; echo "$cmd"; })"; } >> $HISTORY_FILE'
chmod 600 /var/log/histories/history.log 2>/dev/null