How to monitor the user account history used on a Linux server

Source: Internet
Author: User
Tags local time

Monitoring side

Tool Ansible


Scheduled Tasks

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

Build Scripts

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 after installation, rename ansible, and then create a soft link

Mv/usr/bin_ansible/usr/bin/remote_ansi



Client

# echo "Export histtimeformat= ' [%F%T] '" >>/etc/profile

Then modify the/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


This script can let the new end user to collect the log port function, to let the current user can also be collected logs, you need to modify the existence of the user side plus directory lower

. bash_logout file

The content is the same as above, note that the/tmp/all_history file permission must be 777



Once this is done, you can monitor all user-side operation history on the server.


This article is from the "Autumn Song" blog, please be sure to keep this source http://qiufengsong.blog.51cto.com/7520243/1565687

How to monitor the user account history used on a Linux server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.