Thursday, December 3, 2009

In Linux how to send messages within a shell terminal to other logged in users?

Here I’m posting three common methods that you can communicate and send messages between users in shell terminal in Linux.

First let’s start off with a traditional long method... i.e., using the echo method, this seems to be a bit tricky... :)

For this you have to know the terminals on which the users are logged in, so find this out using “who" command.

By this you can know which users are logged into which terminal, so to send a msg to a particular user u have to

Echo the message and redirect that to the terminal in which he is working on..

Example:

root@localhost:/# who

root          tty1          Dec 2       17:57

Chandu    tty3         Dec 2        18:43

Vimal        tty2         Dec 2        18:08

To send msg to user Vimal type :

root@localhost:/# echo “Hi Vimal” > tty2

The second and third methods are very easy and useful. Most of the kernel is compiled with the package, i.e. wall and write.

Second method - The wall command:

Wall is a command to send message to everyone in the shell terminal, in the other word means broadcast the message.

(Refer Wall Man page)

Example:

root@localhost:/# wall (press Enter)

Hello Testing...broadcast using wall (Ctrl-D to broadcast)

Broadcast Message from josephlee@localhost

(/dev/pts/2) at 22:21...

Hello Testing...broadcast using wall

root@localhost:/#

By wall command we can send messages to all logged in users or to users belonging to a particular group.( Using the -g option)

Third method - The write command:

Write is a command to send message to a specify user in the shell terminal. Normally you will also need "who" or "w" command to find out who is in the terminal.

(Refer Write Man page)

Example:

root@localhost:/# write testuser (press Enter)

Testing 123... (Ctrl-D to send)

Message from josephlee@localhost on pts/2 at 22:26...

Testing 123...

EOF

root@localhost:/#

 
Things You Should Know About Linux !!!