1

If I call command systemctl without grep, then formatting looks correctly:

enter image description here

Now I want to filter only lines with 'yarn', but this time line is broken into two parts:

enter image description here

same happens when console is two times wider. How can i fix this?

4

When systemctl’s output isn’t sent to a terminal, e.g. if it’s piped to grep, then it allows each column of its output to grow as much as necessary to fit the longest item in the list. This is what’s happening here: some unit in the list of units has a very long name, and aligning the output of all units produces the large space between yarn.service and loaded failed failed.

To filter the unit output, use systemctl’s built-in pattern matching:

sudo systemctl list-units '*yarn*'

You can limit the output to the lines you’d get with grep with the --no-legend option, avoid colouring and special characters with the --plain option, and avoid starting a pager with the --no-pager option:

sudo systemctl list-units --plain --no-legend --no-pager '*yarn*'

There are better sub-commands if you want to retrieve the status of specific units; see for example The "proper" way to test if a service is running in a script.

  • sudo systemctl list-units --plain --no-legend --no-pager | grep 'yarn' still gives broken lines, its not clear how to pass regexp to systemctl, 'yarn|hdfs' doesnt work – stiv Oct 10 '18 at 13:10
  • Of course sudo systemctl list-units --plain --no-legend --no-pager | grep 'yarn' gives broken lines, that’s explained in the first part of my answer. You need to filter using systemctl. You can specify multiple patterns: sudo systemctl list-units '*yarn*' '*hdfs*' (and please update your question to explain what you’re really after). – Stephen Kitt Oct 10 '18 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.