0

How do I suppress the dot that gets printed to the left of the service name when I run systemctl status XXX? I'd like to save the output of this command to a bash variable and print it. The presence of the dot in the output causes my script to fail, most probably because the dot is a unicode char.

# systemctl status network
● network.service - LSB: Bring up/down networking
   Loaded: loaded (/etc/rc.d/init.d/network; bad; vendor preset: disabled)
   Active: active (exited) since Thu 2018-10-11 09:16:29 PDT; 6h ago
     Docs: man:systemd-sysv-generator(8)

Oct 11 09:16:24 172.100.139.200 systemd[1]: Starting LSB: Bring up/down networking...
Oct 11 09:16:24 172.100.139.200 network[1376]: Bringing up loopback interface:  [  OK  ]
Oct 11 09:16:28 172.100.139.200 network[1376]: Bringing up interface eth0:  [  OK  ]
Oct 11 09:16:29 172.100.139.200 systemd[1]: Started LSB: Bring up/down networking.
  • 2
    Perhaps systemctl status network | tr -d '●'? – doneal24 Oct 11 '18 at 22:28
  • This might be the solution I am seeking. Thanks – linuxfan Oct 11 '18 at 23:11
5

If the problem you're trying to solve is to avoid Unicode characters as part of the output, then you can call the systemd command with a locale setting that does not use UTF-8, in which case systemd will print a * instead of the dot.

You can temporarily set a non UTF-8 locale to a single command by setting the LC_CTYPE variable to something like C or POSIX.

For example:

# LC_CTYPE=C systemctl status network
* network.service - LSB: Bring up/down networking
   Loaded: loaded (/etc/rc.d/init.d/network; bad; vendor preset: disabled)
   Active: active (exited) since Thu 2018-10-11 09:16:29 PDT; 6h ago
     Docs: man:systemd-sysv-generator(8)

Oct 11 09:16:24 172.100.139.200 systemd[1]: Starting LSB: Bring up/down networking...
Oct 11 09:16:24 172.100.139.200 network[1376]: Bringing up loopback interface:  [  OK  ]
Oct 11 09:16:28 172.100.139.200 network[1376]: Bringing up interface eth0:  [  OK  ]
Oct 11 09:16:29 172.100.139.200 systemd[1]: Started LSB: Bring up/down networking.
  • 1
    Excellent. Just the answer I needed. – linuxfan Oct 12 '18 at 1:56
2

See man systemctl:

status

This function is intended to generate human-readable output. If you are looking for computer-parsable output, use show instead. ...

show

To select specific properties to show, use --property=. This command is intended to be used whenever computer-parsable output is required.

  • I looked at the show option and it isn't in a format that I like/want. I'd like to get the same output as systemctl status xxx emits, but without the annoying dot. – linuxfan Oct 11 '18 at 23:01
  • @linuxfan sure, what would Lennart know about parsing text anyway... – jasonwryan Oct 11 '18 at 23:14
  • I'm not questioning Lennart's knowledge of text parsing. Doug has provided a satisfactory answer to my question. – linuxfan Oct 11 '18 at 23:39

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.