Friday, April 23, 2021

how to send broadcast messages to all currently logged on users in linux ?

 Wall displays the contents of a file or, by default, its standard input, on the terminals of all currently logged-in users. The command will cut over 79 character long lines to new lines. Short lines are white space padded to have 79 characters. The command will always put the carriage return and new line at the end of each line.


Only the super-user can write on the terminals of users who have chosen to deny messages or are using a program that automatically denies messages.


Reading from a file is refused when the invoker is not a superuser and the program is suid or sgid.


Usually, system administrators send messages to announce maintenance and ask users to log out and close all open programs. The messages are shown to all logged-in users with a terminal open.


Syntax:


wall [-n] [-t timeout] [message | file]




The most straightforward way to broadcast a message is to invoke the wall command with the message as the argument:


Example: 


wall "The system will be restarted in 10 minutes."


Output:


Broadcast message fromroot@linuxforfreshers (pts/0) (Mon Jan  4 13:22:07 2021):


The system will be restarted in 10 minutes.


The message will be broadcasted to all users that are currently logged in.



To suppress the banner and show only the text you types to the logged-in users, invoke the command with the -n (--nobanner) option:


Example: 


wall -n "The system will be restarted in 10 minutes."


Output: 

The system will be restarted in 10 minutes.




If you want to write multi-line messages, invoke the command without an argument:


wall


The wall command will wait for you to enter text. When you’re done typing the message, press Ctrl+D to end the program and broadcast the message.



You can also use the here-string redirection or pipe the output of another command to wall. Here is an example showing how to use the echo command to broadcast multi-line messages:


Example:


echo "The system will be restarted in 10 minutes. \nPlease save your work."  | wall


Output:


Broadcast Message from root@linuxforfreshers                                       

        (/dev/pts/1) at 13:36 ...                                              

                                                                               

The system will be restarted in 10 minutes. \nPlease save your work.        


Broadcasting a Message From a File 


If you are regularly sending the same messages, you can write each one of them to a file, so that you don’t need to re-type the same text. wall reads from the file only when invoked as root.


To broadcast the contents of a file, invoke the wall command followed by the file name:


cat message1_file.txt

The system will be restarted in 10 minutes.


Example:


wall message1_file.txt


OUTPUT:


Broadcast message from root@linuxforfreshers (pts/0) (Mon Jan  4 13:30:07 2021):


The system will be restarted in 10 minutes.


No comments:

Post a Comment