记录每个用户的操作记录的脚本

dateStamp=`date +"[%F %T]"`

dateDir="`date +%Y`/`date +%m`/`date +%d`"

curHistory=`history 1`

user=`/usr/bin/whoami`

realUserInfor=`/usr/bin/who -u am i|awk '{print $1,$2,$3"~"$4,$7}'`

if [ ! -e $logDir ];then

mkdir -p $logDir

chmod 777 $logDir

fi

logDateDir=$logDir/$dateDir

if [ ! -e $logDateDir ];then

mkdir -p $logDateDir

chmod -R 777 $logDir 2>/dev/null

fi

accountLogDir=$logDateDir/${user:=`hostname`}

if [ ! -e $accountLogDir ];then

mkdir -p $accountLogDir

#chmod 777 $accountLogDir

fi

accountLogName=${user:=`hostname`}.his

accountLog=$accountLogDir/$accountLogName

if [ ! -e "$accountLog" ];then

touch $accountLog

#chmod 777 $accountLog

fi

echo "$realUserInfor $dateStamp =>$curHistory" >>$accountLog

}

export PROMPT_COMMAND=historyLog

[root@localhost ~]# chmod +x /etc/profile.d/accountlog.sh

三、以后每个用户登录的操作都会在/data/accountlog记录


[root@localhost data]# cd accountlog/

[root@localhost accountlog]# ls

2012

[root@localhost accountlog]# cd 2012/

[root@localhost 2012]# ls

01  02  03  04  05  06  07

[root@localhost 2012]# cd 07/

[root@localhost 07]# ls

09  10  12  13  14  15  16  19  20  21

[root@localhost 07]# cd 21

[root@localhost 21]# ls

root

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/ef7345cc421faaf852ba21abe353e29c.html