Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Shell Script To Broadcast A Message

  • Last Updated : 17 Sep, 2021

In this article, we are going to see how to broadcast the message using a shell script in Linux.

Sending a message to a specified user logged in to the terminal: 

Firstly, we will create a .sh file using gedit command. This gedit  is a powerful text editor in linux which is a default text editor for GNOME desktop environment.

Let us try sending a message to the terminal of a specific user:

Step 1: First initialize the text editor by using the below command:

$ gedit messg.sh

here, “messg.sh” is the text file we created to execute the script. 



Step 2: In messg.sh, the following is the script that is involved.

#!/bin/bash
write pavan << End_Of_Message
Hello User, how are you today?
End_Of_Message
echo " message is sent to the requested specific user" 

Step 3: Now, let us enable the script to be executable 

$.chmod +x messg.sh 

Step 4: Now, let us execute the bash script : 

$./messg.sh 

Broadcast message:

Script to broadcast a message from a file : 

First, we will create a .sh file using gedit command. Then, let us try Broadcasting the message from this bash Script .sh file.

Step 1: First initialize the text editor by using the below command:

$gedit messg1.sh 

Here, “messg1.sh” is the text file we created to execute the script. 



Step 2: In mess1.sh, the following is the script that is involved:

#!/bin/bash
wall << End_Of_Message
Hello users, important announcement, machines will be rebooted at 5 pm IST.
End_Of_Message 

Step 3: Now, let us enable the script file to be executable:

$chmod +x messg1.sh 

Step 4: Now, let us execute the bash script file : messg2.sh

$./messg1.sh 

Broadcasting message to a group of users:

First, we will create a .sh file using gedit command. Then, let us try Broadcasting the message from this bash Script .sh file.

we have a users group named “grp1” which contains the following users : 

ravi_teja
pavan
teja 

Now, the user ravi_teja will send an important announcement specific to this grp1 with the help of a bash script : messg2.sh : 

#!/bin/bash
echo $(wall -g grp1) << End_Of_Message
Hello Users, important announcement, machines will be rebooted at 5 pm IST.
End_Of_Message  

Now, let us enable the script file to be executable :

$chmod +x messg2.sh 

Now let’s execute our bash script:

$./messg2.sh 

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!