【Linux】向Linux登录终端发消息

Date: 2018.6.8


1、参考:

http://blog.sina.com.cn/s/blog_8f0b67a901010xfq.html
https://blog.csdn.net/lv_xinmy/article/details/8585882

2、方法

使用场景:
在一台服务器上可能有很多用户登录在上面,每个用户可能采用不同的终端模拟软件登录,每个用户就是一个终端,我们可以向指定用户发送消息 或者 向服务器上的所有用户终端发送广播消息。

采用xshell或者secureCRT登录Linux系统,向各个登录终端发送消息:

相关命令:
mesg
man mesg:
这里写图片描述
write
man write:
这里写图片描述
wall
man wall:
这里写图片描述
在自己虚拟机Ubuntu上采用不同终端测试结果如下:

1) 首先采用who命令查看登录Linux服务器的终端:who命令

soaringlee@ubuntu:~$ who
soaringlee pts/0        2018-06-10 07:08 (192.168.177.1)

2) 给予pts/1终端接受消息的权限:mesg命令

soaringlee@ubuntu:~$ mesg -v y
write access to your terminal is allowed

3) 从pts/1终端上向pts/0终端上发送消息,并以EOF结束。write命令

pts1:

soaringlee@ubuntu:~$ write soaringlee pts/0
I am pts/0.
Thisis a message for pts/1.
That is gratgeful;

pts0:

soaringlee@ubuntu:~$ 
Message from soaringlee@ubuntu on pts/1 at 07:21 ...
I am pts/0.
Thisis a message for pts/1.
That is gratgeful;
EOF

4) 从一个终端向其他终端发送广播消息:wall命令

soaringlee@ubuntu:~/Desktop$ wall Hello, I am pts/0

Broadcast message from soaringlee@ubuntu (pts/0) (Sun Jun 10 07:37:50 2018):   

Hello, I am pts/0. 
原文地址:https://www.cnblogs.com/SoaringLee/p/10532453.html