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
2

2 Answers 2

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
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.

4
  • Weird, the error I was seeing is now nonexistent.... disabling something twice would through a message to stderr that seemed undirect-able.
    – Schorschi
    Commented May 26, 2021 at 21:08
  • @AdminBee 'verb' is the term used by systemd.
    – Daniel
    Commented Jun 1, 2021 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
    Commented Jun 2, 2021 at 7: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 freedesktop.org/software/systemd/man/systemctl.html
    – Abdull
    Commented Jul 18, 2023 at 9:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .