Sending message via terminal to another logged on user BASH programming

user3012382 picture user3012382 · Nov 20, 2013 · Viewed 63.1k times · Source

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.

Answer

86Vijayanand Nandam picture 86Vijayanand Nandam · Nov 20, 2013

'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