'systemctl short status output format for specific service
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...
Solution 1:[1]
You can try systemctl is-active sshd.service
, systemctl is-enabled sshd.service
and systemctl is-failed sshd.service
.
Solution 2:[2]
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
.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Samuel Verschelde |
Solution 2 | Ian Mackinnon |