1

How to suppress output of systemctl?

I have tried

systemctl --quiet
systemctl -q

and even

systemctl 2>&1 1>/dev/null

none of these seem to work when testing for service is disabled when said service is already disabled?

systemctl -q is-disabled dhcpcd
AdminBee
  • 21,637
  • 21
  • 47
  • 71
Schorschi
  • 49
  • 2
  • 2
    Does this answer your question? [Redirect both stderr and stdout to /dev/null with /bin/sh](https://unix.stackexchange.com/questions/80629/redirect-both-stderr-and-stdout-to-dev-null-with-bin-sh) – Gilles 'SO- stop being evil' May 26 '21 at 17:52
  • I'm looking for the opposite: how do you make "reload" give any feedback? *Why* is there no "--verbose" when it has "--quiet". Still not liking it. – Jürgen A. Erhard Mar 17 '23 at 11:39

2 Answers2

8

systemctl does not support is-disabled option, you probably meant is-enabled. To use it and redirect both stdout and stderr to /dev/null:

systemctl is-enabled dhcpcd >/dev/null 2>&1
Arkadiusz Drabczyk
  • 25,049
  • 5
  • 53
  • 68
2

is-disabled is not a systemctl keyword.

This is closer to what I think you want:

systemctl status service &>/dev/null || echo "is-disabled"

I'm using the shell OR branching operator. That line will print is-disabled if the previous command return an error status which systemctl will do in case the service is disabled. If you want to test if the service is enabled instead you can use && instead of ||. The echo is just an example of a following command.

AdminBee
  • 21,637
  • 21
  • 47
  • 71
Daniel
  • 21
  • 2
  • Weird, the error I was seeing is now nonexistent.... disabling something twice would through a message to stderr that seemed undirect-able. – Schorschi May 26 '21 at 21:08
  • @AdminBee 'verb' is the term used by systemd. – Daniel Jun 01 '21 at 23:05
  • Nothing is carved in stone; you can always (and should :) ) edit your own post to add corrections as you see fit. – AdminBee Jun 02 '21 at 07:13
  • Regarding the current version `systemctl status $SERVICE &>/dev/null || echo "is-disabled"`: echoing "is-disabled" is misleading, as `systemctl` has various nonzero exit statuses, each indicating something specific. And a unit/`$SERVICE` can be *enabled* while `systemctl status $SERVICE` returns a nonzero exit status , See https://www.freedesktop.org/software/systemd/man/systemctl.html – Abdull Jul 18 '23 at 09:39