One day to learn about communication between Linux Users

Source: Internet
Author: User

Based on the previous lessons, I believe that you should have a detailed understanding of users and user groups. So what should I do if I want to see which users are currently logged in and want to communicate with a user in the system? This is what we learned today.
We have talked about the id and finger commands before to view some user information. Let's look at several commands related to user information.

W, who, last, lastlog
W shows the user and what the user is doing.

[Root @ yufei ~] # W
22:54:24 up 44 min, 2 users, load average: 0.00, 0.03, 0.02
User tty from login @ IDLE JCPU PCPU WHAT
Root pts/0 192.168.6.1 0.00 s 0.09 s 0.00 s w
Yufei tty1: 0? 2.01 s 0.11 s pam: TPD-password

Line 1: current system time, start time, number of online users and user load
Row 2: Project description, user name, login terminal, where to log on, login time, load status, and ongoing operations
The content below the third line is the same as that in the second line.

Who displays which users have logged on to the system
To view all the parameters, use-a or-alla parameters directly.
[Root @ yufei ~] # Who-all
System boot
Run-level 5
LOGIN tty2 1876 id = 2
LOGIN tty3 1878 id = 3
LOGIN tty4 1880 id = 4
LOGIN tty6 1888 id = 6
LOGIN tty5 1884 id = 5
Root + pts/0. 2073 (192.168.6.1)
Yufei-tty1 old 2049 (: 0)
Pts/1 0 id =/1 term = 0 exit = 0
This shows the system startup time, running level, and enabled terminal (tty1 ~ 6) The user's login location, process number, and other information. For specific parameters, see help.

Last and lastlog
Last view users logging on to the system
Lastlog

[Root @ yufei ~] # Last
Yufei tty1: 0 Fri Jan 14 21:18 still logged in
Root pts/0 192.168.6.1 Fri Jan 14 21:18 still logged in
Reboot system boot 2.6.32-71. el6.i6 Fri Jan 14)
At the top of the page, you will find such information, which allows you to view the user who finally logged on to the system and the user's login status. Including the system start time and the time when the user logs on to the system.

[Root @ yufei ~] # Lastlog-u root; lastlog-u yufei
Username Port From Latest
Root pts/0 192.168.6.1 Fri Jan 14 21:18:05 + 0800 2011
Username Port From Latest
Yufei ** Never logged in **
Here, we have filtered the login status of the root and yufei users. You can also use lastlog to view the login status of all users in the system, but you will find a problem: yufei user, the following figure shows ** Never logged in **, which is what I don't understand and where is the problem? The user yufei is still logged on through the last check, but it is ** Never logged in ** in lastlog. If it is depressing, it is still the same as restarting, this is also the result of restoring to the initial installation status. If a friend knows the reason, please contact me. Thank you!

OK. Now that you know how to view users, how can you send messages to online users? How can I leave messages to offline users? Next, let's take a look at the solutions to some problems.

Write, wall, and mesg
Write and online user communication information
Next let's take a look at his specific usage
SYNOPSIS
Write user [ttyname]
This is easy to use, followed by the user and then the terminal
Look at the example
[Root @ yufei ~] # Who
Root pts/0 (192.168.6.1)
Yufei tty1 (: 0)
Root pts/1 (192.168.6.1)
Yufei pts/2 (: 0.0)
We can use who to check that the system has a yufei besides the root, so we can send a message to yufei.
[Root @ yufei ~] # Write yufei pts/2
At this time, the system will wait for the input information, enter the following information, and press ctrl + d to end the input.
Hello
Nice to meet you
At this time, the yufei user will be able to receive information on the Terminal (Terminal) (basically at the same time ),

Note: yufei is currently on two terminals, one being tty1 and the other being pts/2. Why? This is because when I log on to the system, it is a graphical interface. I first logged on to the system with the yufei user, and then opened a Terminal on the system ). The system logs on to tty1, and the Terminal is pts/2. If you send a message to yufei on tty1, you cannot see it. You can only send a message to yufei on pts/2. You need to understand it here (in fact, it is very simple. After logging on to the X Desktop, there is no tool for receiving information, just in the X environment ). I don't know what I have said. I hope you can understand it. Leave a message.

The information sent by the above root user to yufei will interrupt his current tool no matter what yufei was doing at the time, the following mesg command controls whether to receive messages from others. But note that the information sent by the root user cannot be rejected.

How can I query the current receiving status?
You can view it directly using mesg. One is y and the other is n.
[Yufei @ yufei ~] $ Mesg
Is y
The setting is also very simple. The mesg is followed by a switch.
[Yufei @ yufei ~] $ Mesg n
Is n
Note: This setting must be in the user's first environment (LOGIN Environment). If it is switched through su, there is no permission to change it.
After the settings are complete, except for sending a yufei message to the root user, yufei cannot receive the information sent by other users.

How can I send a message to a single user if it is sent to all online users? Haha, this is simpler. Use wall directly.
For example
[Root @ yufei ~] # Wall "I will shutdown this system! "
At this time, all online users will receive this message.
Note: In the above information, the last one! There must be a space between "and", because the SHELL syntax contains !, So pay attention to it. In general, if the command is followed by a long string of content, we will use "" to include them.

Send messages to offline users
All of the above are sending messages to online users. How can I send messages to offline users? That is the most frequently used mail. Do we still remember that there was a user's email address when talking about users and groups? By the way, this is the user email address under/var/spool/mail.
Because there are many mail parameters, we do not need to study them too deeply. In the course of setting up the server, we will also explain how to set up the mail server, here we will just give you a brief introduction.
The mail format is as follows (in RHEL6)
[Root @ yufei ~] # Mail yufei
Subject: test send mail
Enter the mail title above and the mail content below
Hello, yufei
Nice to meet you!
.
End.
EOT
At this time, the email sent to yufei is complete. Let's replace it with the yufei identity to check it.
[Root @ yufei ~] # Su-yufei
[Yufei @ yufei ~] $ Mail
Heirloom Mail version 12.4 7/29/08. Type? For help.
"/Var/spool/mail/yufei": 1 message 1 new
> N 1 root Fri Jan 14 19/603 "test send mail"
&
In this case, enter 1 to view the specific content of the email,
Message 1:
From root@yufei.opsers.org Fri Jan 14 23:08:09 2011
Return-Path: <root@yufei.opsers.org>
X-Original-To: yufei
Delivered-To: yufei@yufei.opsers.org
Date: Fri, 14 Jan 2011 23:08:09 + 0800
To: yufei@yufei.opsers.org
Subject: test send mail
User-Agent: Heirloom mailx 12.4 7/29/08
Content-Type: text/plain; charset = us-ascii
From: root@yufei.opsers.org (root)
Status: R
The content of the preceding email is clearly displayed,
For more commands, enter "help" after "&".
& Quit
Held 1 message in/var/spool/mail/yufei
You have mail in/var/spool/mail/yufei
This will exit. If you still want to view the email, use mail to view it. If you do not want to ask for this email again, delete 1 can be used to delete the email.

Hello, yufei
Nice to meet you!

&

At this point, all the content about users and user groups has been finished. If you have any questions, please leave a message with me and we will discuss and study it together.

From: yufei blog

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.