如何監控linux服務器上所用用戶帳號 歷史

監控端vim

工具  ansiblebash


計劃任務服務器

*/10 * * * * /dev/shm/history_log.shide

構建腳本工具

vim /dev/shm/history_log.sh spa

#!/bin/bash日誌

function history_log(){rem

local time get

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

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



這樣作完後,就能夠監控服務器上全部用戶端操做歷史了。

相關文章
相關標籤/搜索