linux 记录用户操作日志
将以下加入到/etc/profile 最后
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 700 /tmp/dbasky/${LOGNAME}
fi
export HISTSIZE=4096
DT=`date +%Y%m%d_%H-%M-%S`
# file=`find /tmp/dbasky/${LOGNAME}/ |awk '/'$DT'$/'`
file=/tmp/dbasky/${LOGNAME}/${USER_IP}-record.$DT
if [ -e "$file" ]
then
export HISTFILE="/tmp/dbasky/${LOGNAME}/${USER_IP}-record.$DT.tmp"
tmpfile=/tmp/dbasky/${LOGNAME}/${USER_IP}-record.$DT.tmp
if [ -e "$tmpfile" ]
then
cat /tmp/dbasky/${LOGNAME}/${USER_IP}-record.$DT.tmp >> $file
fi
else
export HISTFILE="/tmp/dbasky/${LOGNAME}/${USER_IP}.$DT"
fi
rm -f /tmp/dbasky/${LOGNAME}/${USER_IP}-record.$DT.tmp
chmod 600 /tmp/dbasky/${LOGNAME}/*record* 2>/dev/null