Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending message via terminal to another logged on user BASH programming

Tags:

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.

like image 261
user3012382 Avatar asked Nov 20 '13 09:11

user3012382


People also ask

How do you send a message to another user in Linux?

Now to send messages to all users, use the wall command, it comes pre-installed in all Linux Distributions which will allow us to send messages to another user in the terminal using tty2. You can use any symbol, character, or white space in the message.

Which command can be used to send a message to all logged in users?

The wall command (as in "write all") allows you to send a message to all users who are currently logged into the system.

How do I send a broadcast message in Linux terminal?

Broadcasting a Message To see all the logged-in users, run the w or who command. The wall command will wait for you to enter text. When you're done typing the message, press Ctrl+D to end the program and broadcast the message.


2 Answers

'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 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 
like image 132
86Vijayanand Nandam Avatar answered Sep 17 '22 17:09

86Vijayanand Nandam


In Linux everything is treated as file system, Each terminal has its file that can seen by who command.

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

Eg:

> write username pts/0

Note: to exit from typing message, use Ctrl+z.

like image 29
chetan h Avatar answered Sep 17 '22 17:09

chetan h