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

Similar Reads
How to Create a Shell Script in linux Shell is an interface of the operating system. It accepts commands from users and interprets them to the operating system. If you want to run a bunch of commands together, you can do so by creating a shell script. Shell scripts are very useful if you need to do a task routinely, like taking a backup
7 min read
Shell Scripting - Dialog Boxes In this article, we will create a shell script that generates a Dialog Box with GUI generating a message to the user. What is a Dialog Box? A Dialog Box is a temporary window an application runs to convey important information to the users. These dialog boxes can be used to display warnings, errors,
7 min read
Shell Scripting - How to send Signal to a Processes Signals allow the operating system to communicate with programs(or processes). There are about 30 standard signals implemented by the Linux OS. We can send signals to processes via certain keyword strokes or by the kill or wait command. Prerequisites: Processes, Bash Scripting, Shell Function Librar
5 min read
Shell script to send email In today's fast-paced digital world, email remains one of the most essential communication tools. Whether it's for business correspondence, personal communication, or automated notifications, sending emails efficiently is crucial. Shell scripting offers a powerful way to automate various tasks, incl
4 min read
Introduction to Linux Shell and Shell Scripting If we are using any major operating system, we are indirectly interacting with the shell. While running Ubuntu, Linux Mint, or any other Linux distribution, we are interacting with the shell by using the terminal. In this article we will discuss Linux shells and shell scripting so before understandi
8 min read