通过终端向另一个登录用户 BASH 编程发送消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20091681/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Sending message via terminal to another logged on user BASH programming
提问by user3012382
Do you have suggestions how to write a script which detects whether the user specified at the first parameter of the script is logged?
你有什么建议如何编写一个脚本来检测在脚本的第一个参数中指定的用户是否被记录?
If you are logged on, offer him the opportunity to write a message to the user. Subsequently, as the message sent will be offered the opportunity to write another report or completing the work of the script.
如果您已登录,请为他提供向用户写消息的机会。随后,作为发送的消息将有机会写另一份报告或完成脚本的工作。
In the case of not user is logged on and the message "" is unknown ...
在没有用户登录并且消息“”未知的情况下......
Thanks.
谢谢。
回答by 86Vijayanand Nandam
'write' is one of the solution. Run command who
“写”是解决方案之一。运行命令谁
who
the output will be something like
输出将类似于
nand pts/1 2013-11-20 11:59 (:0)
nand pts/7 2013-11-20 13:09 (:0)
Now you can message to user "nand" on pts/1 using write as
现在您可以使用 write as 向 pts/1 上的用户“nand”发送消息
write nand pts/1
Press enter after writing this command then type any message you want to send, the other user will see the output as
写完这个命令后按回车然后输入你想发送的任何消息,其他用户将看到输出为
Message from nand@mypc on pts/19 at 14:54 ...
hi
hi
hello
回答by chetan h
In Linux everything is treated as file system, Each terminal has its file that can seen by who
command.
在 Linux 中,一切都被视为文件系统,每个终端都有可以通过who
命令看到的文件。
Eg:
例如:
> who
Output:
username tty7 2016-01-08 10:36 (:0)
username pts/0 2016-01-08 12:56 (:0.0)
username pts/1 2016-01-08 16:05 (:0.0)
username pts/2 2016-01-08 17:10 (:0.0)
Here username pts/0
is special file for 1st terminal(2nd line in output). Data written to this special file will be displayed 1st terminal
这username pts/0
是第一个终端的特殊文件(输出中的第二行)。写入此特殊文件的数据将显示在第一个终端
Eg:
例如:
> write username pts/0
Note: to exit from typing message, use Ctrl+z.
注意:要退出输入消息,请使用Ctrl+ z。
回答by Mark Setchell
Try using these commands:
尝试使用这些命令:
who
mesg
talk