mgetty Command in Linux



mgetty is a Linux command that allows you to manage and control modems on a system. This command allows incoming connection via a serial line and makes it possible for users to dial into the system using modem. mgetty is often used to set up dial-up services, including allowing remote users to log in to the system. It also supports sending and receiving faxes.

This command is particularly useful in environments where legacy communication methods are still in use or for certain specialized applications. It provides a reliable way to handle modem communication and ensure that incoming calls are properly managed and connected.

Table of Contents

Here is a comprehensive guide to the options available with the mgetty command −

How to Install mgetty Command in Linux?

Linux systems do not come with mgetty preinstalled. You can install it using the package manager available on your system.

For Debian-based systems (like Ubuntu)

sudo apt install mgetty

For Red Hat-based systems (like CentOS)

sudo yum install mgetty

For Arch Linux

sudo pacman -S mgetty

Syntax of mgetty Command

Below is the common syntax for executing the mgetty command in Linux −

mgetty [options]

Where, options are different flags that can be applied to modify the command's execution.

mgetty Command Options

The following table highlights a few of the options that can be applied when using the command mgetty on Linux environment −

Options Description
-k <space> Leave <space> kilobytes free on disk when receiving a fax.
-x <debug level> Set the verbosity level for logging (0 means no logging, 9 is very detailed). Logs are usually stored in /tmp/log_mg.<device>.
-s <speed> Set the port speed, e.g., -s 19200.
-r Indicate that mgetty is running on a direct line with no modem initialization. UUCP locking is still done.
-p <login prompt> Use the specified string to prompt users for their login names, with various tokens for system info.
-n # Pick up the phone after the specified number of rings. Default is 1.
-R <t> Enter "ringback" mode, answering the call only if another call is made within the specified time after the first call is not answered.
-i <issue file> Display the specified issue file before the login prompt instead of /etc/issue, with similar token substitutions as the login prompt.
-D Treat the modem as a data modem only, without attempting fax initialization.
-F Set the modem to fax-only mode, disallowing data calls.
-C <class> Specify how to treat the modem (e.g., auto, cls2, c2.0, data).
-S <g3 file> Send the specified file if a call requests fax polling.
-I <fax id> Use the specified fax station ID for fax identification.
-b Open the port in blocking mode, useful in combination with -r. Default if mgetty is called as getty.
-a Use autobauding, adjusting port speed based on the modem's "CONNECT" response. Generally not recommended; fixing the port speed is preferred.
-m 'expect send ...' Set the chat sequence for modem initialization, using expect/send strings. Example: mgetty -m '"" ATH0 OK'.

Examples of mgetty Command in Linux

The following are a few scenarios showcasing the usage of the Linux mgetty command −

  • Running mgetty as a Daemon
  • Setting a Custom Login Prompt
  • Running on a Direct Line
  • Specifying Port Speed
  • Setting the Number of Rings Before Answering
  • Enabling Autobauding

Running mgetty as a Daemon

To have mgetty run continuously in the background and manage the modem without occupying your terminal, use the -D option −

sudo mgetty -D /dev/ttyS0
mgetty Command in Linux1

In this example, mgetty will monitor the modem connected to /dev/ttyS0 and handle incoming connections in the background, freeing up your terminal for other tasks.

Setting a Custom Login Prompt

You can personalize the login prompt that users see when they connect via the modem by using the -p option followed by your custom message −

sudo mgetty -p "Welcome to MySystem, please login: " /dev/ttyS0
mgetty Command in Linux2

This command makes the login prompt display "Welcome to MySystem, please login:" when users access your system through the modem on port /dev/ttyS0, adding a personalized touch to the login process.

Running on a Direct Line

If your modem is connected directly without needing initialization, you can use the -r option to bypass the initialization steps −

sudo mgetty -r /dev/ttyS0
mgetty Command in Linux3

This command configures mgetty to operate on a direct line for the modem on /dev/ttyS0, simplifying the setup by avoiding unnecessary initialization sequences.

Specifying Port Speed

To set the communication speed of the modem, use the -s option followed by the desired baud rate −

sudo mgetty -s 19200 /dev/ttyS0
mgetty Command in Linux4

This command configures the modem on /dev/ttyS0 to communicate at a speed of 19200 baud, ensuring that the data transfer rate meets your requirements.

Setting the Number of Rings Before Answering

You can control how many times the phone should ring before mgetty picks up by using the -n option −

sudo mgetty -n 3 /dev/ttyS0
mgetty Command in Linux5

This command tells mgetty to answer incoming calls after the third ring on port /dev/ttyS0, which can be useful to distinguish between voice and data calls or to avoid premature answering.

Enabling Autobauding

To automatically adjust the port speed based on the modem's connection response, use the -a option −

sudo mgetty -a /dev/ttyS0
mgetty Command in Linux6

This command enables mgetty to dynamically set the port speed according to the modem's "CONNECT" response on /dev/ttyS0, adapting to varying connection speed.

Conclusion

The mgetty is a powerful command for managing modems on Linux systems, offering a range of options to customize its behavior to meet your specific needs.

Whether it's setting custom login prompts, handling fax communications, or running as a background daemon, mgetty provides flexibility and control over modem operations. Understanding these examples will help you effectively use mgetty for various applications.

Advertisements