Sometimes as the administrator of a Linux Operating System Server, y may need to send a message to all users in a multi-user system.
There are some different ways to do this, but we will now see just one of them.
We will use wall.
As the main input of wall is a file, we will first create our message file.
Let’s say you want to tell users that in two more ours the main SQL database is going to be unavailable because of maintenance.
echo 'Please note that in two more hours, you will not be able to use the SQL database. Please save all your work before, and quit any application using it' > message.txt
Now we have our message ready, it is time to send it to the users.
wall < message.txt
And something like this will appear on all terminals open.
Broadcast Message from root@debian
(/dev/pts/1) at 10:06 ...
Please note that in two more hours, you will not be able to use the SQL database. Please save all your work before, and quit any application using it
Traditionally we used wall command to send a message to every user on a network. Unfortunately, wall works over insecure network protocol. Instead of that, we can use wall command over ssh as follows, which is more secure and works with almost all UNIX variant.
Ssh with wall syntax is as follows, after EOF press enter/return key and type message. When the message is complete, type EOF.
$ ssh root@debian wall < EOF
To display message “Kernel is upgraded on this server. System is schedule to reboot in 45-minutes. Please logout and save your work” to ever user on remote system foo.com
$ ssh email@example.com wall < EOF
Kernel is upgraded on this server $(hostname).
System is schedule to reboot in 45-minutes.
Please logout and save your work.
Current local data and time is $(date)
Please note it might prompt for password if ssh-keys not used. Once password supplied it will execute wall command on remote server foo.com. In order to work this remote UNIX/BSD/Linux must have sshd (ssh server) running. Also, notice that we have executed hostname and date command using command substitution feature of shell.