The script records information of all logon users, including the user name, Logon Time, and logon location.

Source: Internet
Author: User

There is a need to record all the login user information, including the user name, Logon Time and logon location to/var/log/login. I have written two scripts here for implementation.

Requirement analysis: the user is simply a root user or a common user;

I can use the whoami or echo $ USER command to view the current logon USER.

[Root @ kissing ~] # Echo $ USER
Root
[Root @ kissing ~] # Whoami
Root

However, you can use the date command to set the logon time.

[Root @ kissing ~] # Date + % y-% m-% d \ % H: % M: % S
13-09-21 00:20:40

There are two types of Logon locations: Local logon and remote logon. How can I determine where a user logs on?

[Root @ kissing ~] # W
00:39:25 up 30 min, 3 users, load average: 0.16, 0.22, 0.18
User tty from login @ IDLE JCPU PCPU WHAT
Root pts/0 192.168.0.102 0.20 s 0.20 s-bash
Root pts/1 192.168.0.102 0.19 s 0.19 s-bash
Root pts/2 192.168.0.102 0.00 s 0.11 s 0.02 s w

From here, we can know that there are terminals at the user's logon location by using the w command, but which is the terminal information of the current user?

There are four administrators logging on, and the users are all root users. Therefore, we cannot use the user to match the appropriate information, but the difference is that the tty can only match the unique data,

Terminal

------ Local terminal tty1-tty6, graphical terminals are all started with:), local terminals are classified as local Login

------- Remote Terminal ssh), remote login is ip_address


After logging on to linux, run the command ps to view the current process.

[Root @ kissing ~] # Ps
PID TTY TIME CMD
2450 pts/2 00:00:00 bash
2485 pts/2 00:00:00 ps

It can be seen that the process I am running is bash

[Root @ kissing ~] # Ps | grep bash
2450 pts/2 00:00:00 bash

[Root @ kissing ~] # Ps | grep bash | grep-v grep | awk '{print $2 }'
Pts/2

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131227/2324252936-0.jpg "title =" 1.jpg" alt = "090621922.jpg"/>

To implement the monitoring function, add the script to the/etc/bashrc file.

######################################## ########################

650) this. width = 650; "src =" http://img1.51cto.com/attachment/201309/091030250.jpg "title =" 2.jpg" alt = "091030250.jpg"/>

Now I will package the two scripts at http://down.51cto.com/data/958043!



This article is from the "oni" blog, please be sure to keep this source http://zhudiqingyin.blog.51cto.com/4018914/1302425

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.