Linux wall Command with Practical Examples

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to use the Linux wall command to send messages to all logged-in users on a system. The lab covers the purpose and syntax of the wall command, how to send a message to all logged-in users, and how to schedule a broadcast message using cron. The lab provides practical examples and step-by-step instructions to help you understand and apply the wall command effectively in your Linux environment.

Linux Commands Cheat Sheet


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("`Linux`")) -.-> linux/SystemInformationandMonitoringGroup(["`System Information and Monitoring`"]) linux(("`Linux`")) -.-> linux/BasicSystemCommandsGroup(["`Basic System Commands`"]) linux(("`Linux`")) -.-> linux/UserandGroupManagementGroup(["`User and Group Management`"]) linux/SystemInformationandMonitoringGroup -.-> linux/crontab("`Job Scheduling`") linux/BasicSystemCommandsGroup -.-> linux/echo("`Text Display`") linux/UserandGroupManagementGroup -.-> linux/sudo("`Privilege Granting`") subgraph Lab Skills linux/crontab -.-> lab-423001{{"`Linux wall Command with Practical Examples`"}} linux/echo -.-> lab-423001{{"`Linux wall Command with Practical Examples`"}} linux/sudo -.-> lab-423001{{"`Linux wall Command with Practical Examples`"}} end

Understand the Purpose and Syntax of the wall Command

In this step, you will learn about the purpose and syntax of the wall command in Linux. The wall command is used to send a message to all logged-in users on a system.

To understand the purpose of the wall command, let's first explore its syntax:

wall [message]

The wall command takes an optional message argument, which will be displayed to all logged-in users. If no message is provided, the wall command will prompt the user to enter the message to be sent.

For example, let's send a message to all logged-in users:

sudo wall "Attention, all users! This is an important announcement."

Example output:

Broadcast message from labex@ubuntu (somewhere) (Fri Mar 10 12:34:56 2023):

Attention, all users! This is an important announcement.

The wall command sends the message to the terminal of each logged-in user, regardless of their current activity or location on the system.

Send a Message to All Logged-in Users

In this step, you will learn how to use the wall command to send a message to all logged-in users on the system.

To send a message to all logged-in users, follow these steps:

  1. Open a terminal on your Ubuntu 22.04 Docker container.

  2. Use the wall command to send a message to all logged-in users. For example:

    sudo wall "This is an important message for all users."

    Example output:

    Broadcast message from labex@ubuntu (somewhere) (Fri Mar 10 12:34:56 2023):
    
    This is an important message for all users.

    The wall command will display the message on the terminal of each logged-in user, regardless of their current activity or location on the system.

  3. Verify that the message was successfully sent by checking the terminals of other logged-in users (if any).

Now, try sending a different message using the wall command and observe the result.

Schedule a Broadcast Message Using cron

In this step, you will learn how to use the cron scheduler to automatically send a broadcast message to all logged-in users at a specific time.

  1. Open a terminal on your Ubuntu 22.04 Docker container.

  2. Use the crontab command to edit the cron schedule for the labex user:

    sudo crontab -e
  3. Add the following line to the crontab file to send a broadcast message every minute:

    * * * * * sudo wall "This is a scheduled broadcast message."

    This cron entry will execute the wall command every minute to send the message "This is a scheduled broadcast message." to all logged-in users.

  4. Save and exit the crontab editor.

  5. Wait for a minute and check the terminals of other logged-in users (if any) to verify that the scheduled broadcast message has been sent.

Now, try modifying the cron schedule to send the broadcast message at a different interval (e.g., every 5 minutes, every hour, etc.) and observe the results.

Summary

In this lab, you learned about the purpose and syntax of the wall command in Linux, which is used to send a message to all logged-in users on a system. You practiced sending a message to all logged-in users using the wall command, and you also learned how to schedule a broadcast message using cron.

The lab covered the key steps of understanding the wall command, sending a message to all logged-in users, and scheduling a broadcast message. These practical examples demonstrate the utility of the wall command in Linux for effectively communicating with all users on a system.

Linux Commands Cheat Sheet

Other Linux Tutorials you may like