Linux is a multi-user operating system that allows multiple users to log in and use the system. This implies that at any given time, you might have several users logged in.
Sometimes, you might need to send a message or notification to all the users without necessarily placing a phone call or sending them emails. This is mostly when you want to announce a maintenance task or instruct them to log out.
In this guide, we will demonstrate how you can send messages to all logged-in users in the system. This only applies to users who are logged in via a terminal window using an SSH client such as PuTTY.
Send Messages to Logged-in Users Using the Wall Command
The wall command is a command-line utility that displays messages to all logged-in users on the terminal.
The wall command takes the following basic syntax:
$ wall OPTION { file | message }
If no file is specified, then the wall command reads the message from standard input and broadcasts it to all logged-in users.
For example, the following command reads the message enclosed in quotation marks as the argument and sends it to all logged-in users
# wall "The system will be shutting down at 1500HRS for maintenance. Apologies for any inconvenience caused".
When viewed from a logged-in user (in this case bob), the message appears as shown on the terminal window.
To display a message from a file, invoke the wall command followed by the file name as shown.
$ wall sample_msg.txt
This is how the user receives the message on the terminal.
Send Messages to a Specific Logged-in User
Alternatively, you can use the write command to send a message to a specific user. To list all the currently logged-in users, invoke the who command:
$ who
For example, to send a message to a user called winnie and notify her about a system restarting in the next 3 hours, run the following write command with the echo command.
$ echo "This system will be restarted in 3 hours" | write winnie
On the user’s terminal, the message will appear as shown.
Conclusion
We have covered various ways of sending a message or notification to logged-in users using the wall and write commands. We hope that you can now send messages to logged-in users without a problem.