systemctl
스크립팅에 적합한 모드가 있습니다. show
대신에 사용 status
하고 -p
/ --properties
및 --value
옵션을 추가하여 원하는 출력 만 얻으십시오.
다음은 Ubuntu 17.04 시스템의 예입니다.
$ systemctl show -p SubState --value NetworkManager
running
달리기 (또는 달리)는입니다 SubState
. 서비스가 활성화되어 있는지 확인하려면이 속성을 사용하십시오.ActiveState
$ systemctl show -p ActiveState --value x11-common
inactive
$ systemctl show -p SubState --value x11-common
dead
의 메모 man
:
show [PATTERN...|JOB...]
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.
-p, --property=
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
property names.
--value
When printing properties with show, only print the value, and
skip the property name and "=".
inactive
또는activating
둘 다systemctl status
이며systemctl is-active
3으로 종료합니다. ( systemd-241 기준 ) 해결책 :systemctl show service | grep -qx ActiveStatus=activating