Shell Scripting - Talk Command
Last Updated :
16 Oct, 2024
The use of Shell scripting can simplify repetitive tasks and enable more complex operations with minimal code. Shell commands vary in syntax, with "talk" being a command to facilitate communication among users within the same network. Proper knowledge of the shell, OS, and available commands is necessary for effective shell scripting.
Familiarity with regular expressions, which are used to match and manipulate text, is also essential. Shell scripting is often utilized with other tools and technologies, such as programming languages, web servers, and databases. In Unix-based systems, the talk command initiates two-way conversations between users.
Dependency of talk Command for Ubuntu and Red Hat
1. For Ubuntu:
The "talk" command was last available in Ubuntu 14.04 LTS, which was released in April 2014. In Ubuntu 14.04, the "talk" command could still be installed and used from the repository. Starting from Ubuntu 16.04 LTS (Xenial Xerus) and subsequent versions, the "talk" command is no longer included in the default installation, and it has been replaced by more modern communication tools.
2. For RED HAT:
In Red Hat Enterprise Linux 6, the "talk" command could still be installed and used from the repository. However, starting from Red Hat Enterprise Linux 7 and subsequent versions, including the latest version RHEL 8, the "talk" command is not included in the default installation and is no longer available in the official repositories. If you are using a recent version of Red Hat Enterprise Linux, such as RHEL 7 or RHEL 8, or RHEL 9 the "talk" command is not available by default.
What is Talk Command
The talk command comes in handy when we need to communicate with different users on the same network. by using them in shell scripts, we can automate tasks like sending notifications for work or any remainder for submission to a bunch of users at the same time. Whether you're using it for simple conversations or more advanced shell scripts, the talk command is an essential tool for any Unix-based system administrator. Shell scripts are very useful in automating tasks. we can also do some projects based on shell scripts and talk commands.
Syntax
talk user@host
where,
- user: The username of the person you want to communicate with.
- host: The hostname or IP address of the computer where the user is logged in.
Usage of Talk Command
For example, to talk with someone named John who is logged in with the hostname example.com, you can use the command mentioned below:
talk [email protected]
Once the command is executed, a new window will open, allowing you to communicate with the other user in real-time. The conversation will continue until one of the users closes the window or types "exit".
Options Available for the talk Command
Talk command can also be used with some options, some of which are mentioned below:
Options | Description |
---|
-f | used to initiate the conversation in full-screen mode. |
---|
-n | used to prevent the other user from being notified when the conversation is initiated. |
---|
-w | used to set the width of the conversation window. |
---|
-W | used to set the width of the conversation window to the entire width of the screen. |
---|
For example, if we want to initiate a full-screen conversation with a user named "John" without sending them a notification, we would use the following command:
talk -fn [email protected]
Talk Command in Shell Script
The talk command can also be used in shell scripts to perform automated tasks, such as sending notifications to other users or initiating conversations with specific users. For example, the following script can be used to send a notification to all users on a network.
Example 1: Send a notification to all users on the same network
This script uses an array to store a list of users and then uses a loop to iterate through the array, sending a notification to each user using the talk command.
Script:
This script will send a notification message, "This is a notification from the system." to the email addresses [email protected], [email protected], and [email protected] using the 'talk' command. The script will not produce any output on the command line.
// below line is called a shebang, and it tells the shell that this script should be run using the Bash interpreter.
#!/bin/bash
// below line defines an array called users with three elements: "user1", "user2", and "user3".
users=( "user1" "user2" "user3" )
// below line starts a for loop that will iterate over each element in the user's array. The "${users[@]}" part specifies that the
loop should iterate over each element in the array.
for user in "${users[@]}"
// below line starts the block of code that should be executed for each iteration of the for loop.
do
// below line uses the talk command to send a message to each user's email address. The -n option tells talk not to wait for a
response, and the <<< operator is used to pass the message as input to the talk command. The $user variable is replaced with
the current user's name.
talk -n [email protected] <<< "This is a notification from the system."
done
Output:
Send a notification to all users on the same networkExample 2: Send a notification to a specific user on a Network
Here is a simple script that uses the "talk" command to send a message to a user named "john" on a machine with the hostname "example.com".
Script:
The following script initiates a dialogue with a specified user. It first defines a variable, "message," containing the message you want to convey. Next, it uses the "talk" function along with the user's username and hostname to begin a dialogue with them.
The <<< operator is used to redirect the message variable to the talk function.
#!/bin/bash
# Storing message in variable
message="Hello, this is a message sent using the talk command."
# Use to send the message
talk [email protected] <<< $message
Output:
Send a notification to a specific user on a NetworkConclusion
The talk command in Linux, though somewhat outdated, remains a powerful tool for real-time communication and automation when used in shell scripts. By leveraging the talk command, system administrators can automate the sending of messages and notifications across networks. Although newer communication tools have replaced talk in many systems, it still provides value in specific environments and for educational purposes.
Similar Reads
Shell Scripting - True Command A shell provides an interface with the help of which users can interact with the system easily. To directly interact with a shell, we use an operating system. On a Unix-based operating system, every time we write a command using a terminal, we interact with the system. To interpret or analyze Unix c
3 min read
Shell Scripting - Set Command The `set` command in shell scripting is a powerful tool that used for controlling the behavior of the shell and the environment in which scripts run. It allows the users to modify the shell options and positional parameters which facilitates providing greater control over script execution and debugg
6 min read
Shell Scripting - Command Substitution A shell is an interface that helps users to connect with the system. Using a shell is equivalent to indirectly communicating with the operating system. In Linux distributed systems, each time we use the terminal, we connect with a shell. The job of a shell is to analyze Unix commands or instructions
4 min read
talk command in linux In Linux, there are commands like write/wall which are used to communicate with other users especially by system administrators to send a short message to all logged-in users. There is one more command talk which is like an instant messenger service that enables two users to chat. In this article, w
3 min read
How to Use Heredoc in Shell Scripting The Heredoc or Here Document is an input literal used by many programming and scripting languages. The Heredoc was originally used in UNIX Shells and is in fashion till date and, is supported by all popular Linux shells such as zsh, bash, tsh, etc. The symbol for a Heredoc is '<<' two left che
6 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 - Define #!/bin/bash A shell provides an interface to connect with the system. When we use an operating system, we indirectly interact with the shell. While using a terminal every time on any Linux distribution system, we interact with the shell. The main function of the shell is to interpret or analyze Unix commands. A
3 min read
How to execute shell command in Ruby? Ruby is also known for its simplicity and versatile nature, it provides various methods for executing shell commands within your scripts. Whether you need to interact with the underlying operating system or automate tasks, Ruby offers several approaches to seamlessly integrate shell commands into yo
3 min read
Shell Script to Demonstrate Wait Command in Linux Wait command is one of the process management commands. There are different process commands in Linux mainly 5 commands are widely used which are ps, wait, sleep, kill, exit. ps is an acronym for process status. It displays information about the active processes. wait command will suspend execution
4 min read
Telnet Command in Linux Telnet serves as a command line interface (CLI) tool that allows logging in and communication with a system through a TCP/IP network. Users can issue commands on a remote machine as Telnet users can log into a machine over a TCP/IP network with the use of Telnet addresses (e.g. telnet://user@hostnam
7 min read