How to broadcast a message to all users and direct message to some user
Administrators have several ways to send messages to everyone logged in to a text-mode system. This article introduces two simple methods: broadcasting a message to all logged-in users and sending a message directly to a particular user. Both methods are described below.
-
Broadcasting a message to all logged-in users Use “wall” to broadcast the message, and “echo” to print the text you want to send. Command syntax
[user1Ezylinux ~]$ echo -e "Text for send" | wallThe message every user receives
Broadcast message from [email protected] (Mon Nov 14 21:13:06 2011): Text for sendTo include line breaks, add “\n” at the end of each line. Example
[user1Ezylinux ~]$ echo -e 'Message1 \nMessage2' |wall Broadcast message from [email protected] (Mon Nov 14 21:13:18 2011): Message1 Message2 -
Sending a message directly to a particular user First find the TTY on which the intended recipient is logged in using “w”.
[user1Ezylinux ~]$ w 21:50:47 up 58 days, 21:27, 3 users, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT user1 pts/1 56.7.8.8 20:57 0.00s 0.04s 0.00s w user2 pts/2 56.7.8.9 20:57 37:29 0.00s 0.00s -bash user3 pts/3 56.7.8.10 21:13 26:25 0.00s 0.01s sshd: user3 [priv]Look at the TTY column to identify the user’s pts or tty. Then use “echo” to send text to /dev/pts/n, where n is the terminal number. For example, I am user1 and want to send “Message1” directly to user2. The output of “w” shows that user2 is on pts/2, so use this command:
[user1Ezylinux ~]$ echo -e "\nMessage1" > /dev/pts/2user2 receives the following message:
[user2Ezylinux ~]$ Message1