一下腳本需添加至
/etc/profile
腳本如下:
# file name record1.0
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/operation ]
then
mkdir /tmp/operation
chmod 777 /tmp/operation
fi
if [ ! -d /tmp/operation/${LOGNAME} ]
then
mkdir /tmp/operation/${LOGNAME}
chmod 700 /tmp/operation/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date +%Y%m%d`
# file=`find /tmp/operation/${LOGNAME}/ |awk '/'$DT'$/'`
file=/tmp/operation/${LOGNAME}/${USER_IP}-susworld.$DT
if [ -e "$file" ]
then
export HISTFILE="/tmp/operation/${LOGNAME}/${USER_IP}-susworld.$DT.tmp"
tmpfile=/tmp/operation/${LOGNAME}/${USER_IP}-susworld.$DT.tmp
if [ -e "$tmpfile" ]
then
cat /tmp/operation/${LOGNAME}/${USER_IP}-susworld.$DT.tmp >> $file
fi
else
export HISTFILE="/tmp/operation/${LOGNAME}/${USER_IP}-susworld.$DT"
fi
rm -f /tmp/operation/${LOGNAME}/${USER_IP}-susworld.$DT.tmp
chmod 600 /tmp/operation/${LOGNAME}/*susworld* 2>/dev/null
該腳本將記錄凡用戶登陸後進行的任何操作,並生成對應用戶當日的操作日志共日後查詢。
如有更優化腳本,望指教。
附上方便查詢歷史操作的shell:http://www.linuxidc.com/Linux/2011-05/36402.htm
配合此shell,使用起來更加方便。
這兩個shell均本人所寫,如有建議,希望交流。