initlog Command in Linux



The initlog command in Linux logs messages and events to the system logger. It is designed to be used with init scripts. The init scripts are the scripts that run during system boot or shutdown.

The initlog command reads the configuration from the /etc/initlog.conf file to determine its settings. However, command line options can also set the command’s behavior.

Table of Contents

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

Note − The initlog command has been deprecated and may not be available in recent versions of Linux distributions. It is deprecated due to the wide adoption of systemd. The initlog was a part of System V. The systemd init system uses journald for logging and offers more advanced functionality than initlog.

Syntax of initlog Command

The syntax of the Linux initlog command is as follows −

initlog [options]

The [options] field is used to specify various options to change the command behavior.

Options of initlog Command

The options of the initlog command are listed below −

Flags Options Description
-c program --cmd= program It runs a program and logs its output
-e number --event= number It logs a specified event used with --name (1=action completed, 2=action failed, 3=action cancelled, 4=action failed due to dependent action failure)
-f facility --facility= facility It sets the syslog facility (default=daemon)
-n string --name= string It logs the event by a specified name
-p priority --priority= priority It logs according to specified priority (default=notice)
-q It suppresses the output unless there is an error
-r program --run= program It executes the specified program and logs the output, maintaining an open file descriptor for command exchange
-s string --string= string It logs the specified string to the logger
--conf= file It is used to specify a different configuration file instead of /etc/initlog.conf

Understanding the initlog Configuration File

The initlog reads the default configuration file to determine its operations. The initlog configuration file is located in /etc/initlog.conf. It is used to set various options to set how messages should be logged.

The directives recognized by /etc/initlog.conf file are listed below −

Directives Description
facility <logging facility> To set the default logging facility, for example, daemon, local0, or auth
priority <priority> To set the logging priority, for example, info, warning, or notice
ignore <pattern> To set a regex pattern to ignore specific messages from logging

The # sign is used to specify comments in the file. A typical initlog configuration file is shown in the following image −

initlog Command in Linux1

Examples of initlog Command in Linux

This section demonstrates the usage of the initlog command in Linux with examples −

Logging a String

To log a string with the default facility (daemon) and default priority (notice), use the initlog command in the following way −

initlog -s "system rebooted"

Logging an Event

To log an event with a custom name, use the -e and -n options −

initlog -e 1 -n "myEvent"

The 1 indicates the success event. It will log the completion of the myEvent action.

Logging Specific Command Output

To log the specific command output, use the -c or --cmd option −

initlog -c ls

Logging with a Different Facility and Priority

To log a string with a different facility and priority, use the initlog command in the following way −

initlog -f local0 -p warning -s "memory low"

Reading Configuration from a Different Location

By default, the initlog command reads the /initlog.conf file located in /etc. To read a different file, use the --conf option with the file location −

initlog --conf=/home/user/mylogFile.conf -s "memory low"

Conclusion

The initlog command in Linux logs messages and events. It is deprecated because it was a part of System V init system. System V has largely been replaced by the systemd init system, which uses journald for logging. The journald is much more advanced and flexible compared to initlog.

In this tutorial, we explained the initlog command, its syntax, options configuration file, and usage through examples.

Advertisements