Reputation: 633
is it possible to get status for specific systemd service
$ systemctl -a | grep sshd.service
sshd.service loaded active running OpenSSH server daemon
$
but without grep, only with systemctl ? Something like systemctl SHOW_STATUS_LIKE_A_OPTION sshd.service
systemctl status
- too long and multiline...
Upvotes: 24
Views: 14615
Reputation: 416
Example:
$ systemctl list-units -q amsd.service smad.service cpqIde.service cpqFca.service cpqiScsi.service cpqScsi.service
amsd.service loaded active running Agentless Management Service daemon
cpqIde.service loaded active running cpqIde MIB handler.
cpqiScsi.service loaded active running cpqiScsi MIB handler.
cpqScsi.service loaded active running cpqScsi MIB handler.
smad.service loaded active running System Management Assistant daemon
To avoid having to provide the .service
suffix, I tried --type service
, with service names only, but got empty printout:
$ systemctl list-units --type service -q amsd smad cpqIde cpqFca cpqiScsi cpqScsi
$
The following works just as well:
(s=(amsd smad cpqIde cpqFca cpqiScsi cpqScsi); set -x; systemctl list-units -q ${s[@]/%/.service})
+ systemctl list-units -q amsd.service smad.service cpqIde.service cpqFca.service cpqiScsi.service cpqScsi.service
amsd.service loaded active running Agentless Management Service daemon
cpqIde.service loaded active running cpqIde MIB handler.
cpqiScsi.service loaded active running cpqiScsi MIB handler.
cpqScsi.service loaded active running cpqScsi MIB handler.
smad.service loaded active running System Management Assistant daemon
I wish there were a way to include the "Since" field.
Upvotes: 3
Reputation: 51
The closest is native command is systemctl list-units -t service
:
$ systemctl --user list-units --type service
UNIT LOAD ACTIVE SUB DESCRIPTION
dbus.service loaded active running D-Bus User Message Bus
podman-promtail.service loaded active running rootless pod promtail
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
2 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
Source: Red Hat sys admin docs
Upvotes: 1
Reputation: 14238
Based on Samuel's answer, I offer a simple shell function for .bashrc
, including cheeky use of grep for colorization:
function status () {
for name in $@; do \
echo ${name} $(systemctl is-active ${name}) $(systemctl is-enabled ${name}); \
done | column -t | grep --color=always '\(disabled\|inactive\|$\)'
}
Invocation:
> status ssh ntp snapd
ssh active enabled
ntp active enabled
snapd inactive disabled
Note that is-active
will print inactive
for non-existent services, while is-enabled
will print a warning to stderr
.
Upvotes: 4
Reputation: 372
You can try systemctl is-active sshd.service
, systemctl is-enabled sshd.service
and systemctl is-failed sshd.service
.
Upvotes: 26