systemctl does have a mode suitable for scripting; use
show rather than
status, and add the
--value options to get only the output you want.
Here's an example (from an Ubuntu 17.04 system):
$ systemctl show -p SubState --value NetworkManager
Running (or otherwise) is a
SubState. If you want to know whether a service is active, use the property
$ systemctl show -p ActiveState --value x11-common
$ systemctl show -p SubState --value x11-common
Notes from the
Show properties of one or more units, jobs, or the manager
itself. If no argument is specified, properties of the
manager will be shown. If a unit name is specified, properties
of the unit are shown, and if a job ID is specified,
properties of the job are shown. By default, empty properties
are suppressed. Use --all to show those too. To select specific
properties to show, use --property=. This command is intended
to be used whenever computer-parsable output is required. Use
status if you are looking for formatted human-readable output.
When showing unit/job/manager properties with the show command,
limit display to properties specified in the argument. The
argument should be a comma-separated list of property names,
such as "MainPID". Unless specified, all known properties are
shown. If specified more than once, all properties with the
specified names are shown. Shell completion is implemented for
When printing properties with show, only print the value, and
skip the property name and "=".
To see available properties for a service, run (for example, for
systemctl show -a polkit
There are many properties, so if you know what you're looking for...
$ systemctl show - polkit | grep Active
ActiveEnterTimestamp=Thu 2020-07-02 07:24:40 IST