systemctl 的可解析输出(例如列出所有单元)

gue*_*tli 4 systemd systemctl

我对 systemctl 的输出不满意

我有一个解析输出的脚本

systemctl list-units -t service --full --all
Run Code Online (Sandbox Code Playgroud)

输出的开头如下所示:

  UNIT                                   LOAD      ACTIVE     SUB          JOB   DESCRIPTION                                                                  
  after-local.service                    loaded    inactive   dead               /etc/init.d/after.local Compatibility                                        
? amavis.service                         not-found inactive   dead               amavis.service                                                               
  apparmor.service                       loaded    active     exited             Load AppArmor profiles                                                       
  auditd.service                         loaded    active     running            Security Auditing Service                                   
Run Code Online (Sandbox Code Playgroud)

在不同的系统上,带点的列(在 amavis.service 之前)不存在。

systemctl 是否有机器/脚本可读的输出?

gue*_*tli 12

我将它用于机器可解析的输出,--plain --no-legend例如添加:

systemctl list-units -t service --full --all --plain --no-legend
Run Code Online (Sandbox Code Playgroud)