Linux下跟踪记录每个用户对主机服务器进行的操作
Linux下跟踪记录每个用户对主机服务器进行的操作
一下脚本需添加至/etc/profile 脚本如下: # file name record1.0history 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: 配合此shell,使用起来更加方便。 这两个shell均本人所写,如有建议,希望交流。
评论暂时关闭