码迷,mamicode.com
首页 > 系统相关 > 详细

如何监控linux服务器上所用用户账号 历史

时间:2014-10-20 02:18:43      阅读:238      评论:0      收藏:0      [点我收藏+]

标签:linux 所有用户 操作历史

监控端

工具  ansible


计划任务

*/10 * * * * /dev/shm/history_log.sh

构建脚本

vim /dev/shm/history_log.sh 

#!/bin/bash

function history_log(){

local time 

time=`date -d "-10 min" "+%F %H:%M"`

tim=${time%[0-9]}

remote_ab -h test -c "tail -300 /tmp/all_history"|grep "$tim" >> /tmp/All_history

}

history_log


 which remote_ab

alias remote_ab=‘/dev/shm/remote_ansi‘

/dev/shm/remote_ansi


vim /dev/shm/remote_ansi 

#!/bin/bash

while getopts "h:c:"  opt

do

case $opt in

h)

host=$OPTARG

;;

c)

command=$OPTARG

;;

*)

echo "please click --help "

;;

esac

done


if [ "x$host" != "xtest" -a "x$host" != "xonline" ]

then

echo "make a choise in [ test|online ]"

exit

fi

remote_ansi -i /home/ec2-user/remote_ansi/hosts $host -a "$command"



remote_ab //ansible安装完后,重命名ansible,然后创建软链接  

mv /usr/bin_ansible /usr/bin/remote_ansi



客户端

# echo "export HISTTIMEFORMAT=‘[ %F %T ] ‘ " >> /etc/profile

然后修改/etc/skel/.bash_logout

# ~/.bash_logout

history|awk ‘{$1=""}1‘ > /tmp/history_`whoami`

sed -i "s/^/`hostname` `whoami`/g" /tmp/history_`whoami`

cat /tmp/history_`whoami` >> /tmp/all_history

history -c

> ~/.bash_history


这个脚本可以让新建端用户实现搜集日志端功能,要向让当前存在端用户也可以被搜集日志,就需要修改存在用户端加目录下端

.bash_logout文件

内容与上相同,注意,  /tmp/all_history  文件权限须为777



这样做完后,就可以监控服务器上所有用户端操作历史了。


本文出自 “秋风颂” 博客,请务必保留此出处http://qiufengsong.blog.51cto.com/7520243/1565687

如何监控linux服务器上所用用户账号 历史

标签:linux 所有用户 操作历史

原文地址:http://qiufengsong.blog.51cto.com/7520243/1565687

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!