How to Use the Command 'svcs' (with examples)

How to Use the Command 'svcs' (with examples)

The ‘svcs’ command is used to list information about running services on a Unix-like operating system. It provides details about the services, including their state, status, and log files. This article will illustrate five different use cases of the ‘svcs’ command with examples.

Use case 1: List all running services

Code:

svcs

Motivation: This use case is helpful when you want to get a quick overview of all the services currently running on the system. It helps in determining if all the expected services are operational.

Explanation: The ‘svcs’ command without any argument lists information about all running services. It displays the service name, state (online, offline, maintenance, etc.), and additional status information.

Example output:

STATE          STIME    FMRI
online         13:49:22 svc:/system/picl:default
online         13:49:22 svc:/network/rpc/bind:default
online         13:49:29 svc:/network/rpc/gss:default
offline        May_25   svc:/network/nis/domain:default

Use case 2: List services that are not running

Code:

svcs -vx

Motivation: Identifying services that are not running is crucial for troubleshooting and system maintenance. This use case helps in highlighting services that are down or in a maintenance state.

Explanation: The ‘-vx’ option is used to list services that are not running. It provides detailed information about the services, including the reason for the non-running state.

Example output:

STATE          STIME    FMRI
disabled       Feb_28   svc:/network/ntp:default
maintenance    Mar_15   svc:/system/sshd:default

Use case 3: List information about a service

Code:

svcs apache

Motivation: When troubleshooting a specific service, it is essential to gather information about its current state and status. This use case helps in obtaining detailed information about a particular service.

Explanation: In this example, ‘apache’ is the name of the service for which we want to see information. The ‘svcs’ command retrieves and displays information about the specified service.

Example output:

STATE          STIME    FMRI
online         14:21:27 svc:/network/http:apache2

Use case 4: Show location of service log file

Code:

svcs -L apache

Motivation: For troubleshooting purposes, it is often necessary to access the log files of a service. This use case helps in identifying the location of the log file associated with a specific service.

Explanation: The ‘-L’ option followed by the service name (‘apache’ in this example) is used to display the location of the log file for the given service.

Example output:

/var/svc/log/network-http:apache2.log

Use case 5: Display end of a service log file

Code:

tail $(svcs -L apache)

Motivation: When analyzing log files, it is common to view the most recent entries to identify any errors or warnings. This use case helps in displaying the end portion of a service log file, allowing for quick analysis.

Explanation: The ‘$(svcs -L apache)’ command substitution is used to get the location of the log file for the ‘apache’ service. This location is then passed as the argument to the ’tail’ command, which displays the last few lines of the log file.

Example output:

[2021-05-28 14:23:42.308] (info) apache2: worker initialized [104:0] mod_ssl initialized
[2021-05-28 14:30:25.946] (info) apache2: worker help requested by foundation (505)

Conclusion:

The ‘svcs’ command is a powerful tool for managing and monitoring services on a Unix-like operating system. By using different options and arguments, it provides useful information about running services, their states, status, and log files. Understanding the various use cases of the ‘svcs’ command can greatly assist in troubleshooting and system maintenance activities.

Tags :

Related Posts

How to use the command 'gbp' (with examples)

How to use the command 'gbp' (with examples)

The ‘gbp’ command is a system that integrates the Debian package build system with Git.

Read More
Using the `mssh` Command for Managing Multiple SSH Connections (with examples)

Using the `mssh` Command for Managing Multiple SSH Connections (with examples)

Connecting to Multiple SSH Servers To connect to multiple SSH servers using the mssh command, we can simply provide the usernames and hostnames of the servers as arguments.

Read More
How to Use the Dolt Blame Command (with examples)

How to Use the Dolt Blame Command (with examples)

The Dolt Blame command is a powerful tool that allows users to view commit information for each row of a Dolt table.

Read More