需要将 ssh 输出转换为 json 格式

需要将 ssh 输出转换为 json 格式

我有一段代码,它生成一个块输出。

TIBCO ActiveMatrix BusinessWorks version 6.4.2, hotfix 7, build V103, 2018-07-18 Connecting to the BW Agent using TIBCO ActiveSpaces (Java). Enterprise Edition. Version 2.1.6.011 Connected to BW Agent
Domain: 3APIServices

Name                                               Version  AppSpace                       Profile                        Status          Deployment Status (Running/Total)
AS_CRM_032-CustomerAccount_CRM.application         1.0      AS_CRM_032_AppSpace            PROFILE.substvar               Running         Deployed          (1/1)
a
/home/REBUSCLOUD/kramk/ServiceLive.sh: line 6: /opt1/tibco/tea/2.3/bin/bwadmin: No such file or directory
TIBCO ActiveMatrix BusinessWorks version 6.4.2, hotfix 7, build V103, 2018-07-18
Connecting to the BW Agent using
 TIBCO ActiveSpaces (Java). Enterprise Edition. Version 2.1.6.011
 Connected to BW Agent


Domain: 3APIServices

Name                                               Version  AppSpace                       Profile                        Status          Deployment Status (Running/Total)
AS_DW_021_3APIFailureEvents_DW.application         1.0      AS_DW_021_AppSpace             PROFILE.substvar               Running         Deployed          (1/1)
a
/home/REBUSCLOUD/kramk/ServiceLive.sh: line 6: /opt1/tibco/tea/2.3/bin/bwadmin: No such file or directory
TIBCO ActiveMatrix BusinessWorks version 6.4.2, hotfix 7, build V103, 2018-07-18
Connecting to the BW Agent using
 TIBCO ActiveSpaces (Java). Enterprise Edition. Version 2.1.6.011
 Connected to BW Agent

我需要将输出转换为 json 格式,如下所示

{
            "Domain": "3APIservices",
            "Name": "AS_CRM_032-CustomerAccount_CRM.application",
             "Version": "1.0",
            "Appspace": "AS_CRM_032_AppSpace",
         },

有人可以帮我解决这个问题吗?

下面是我使用的一段代码。由于这是在循环中,我将一一获得输出。问题是我需要将其放在 json 中,以便我可以在其他地方使用它。

for f in ls -d /opt1/tibco/bw/6.4/domains/*/appspaces/*; do
 DomainName="${f%%'/appspaces/'*}"
 DomainName="${DomainName##*/}"
 AppSpaceName="${f##*'/'}"
 Command_To_Execute="/opt1/tibco/bw/6.4/bin/bwadmin --propFile /opt1/tibco/bw/6.4/bin/bwadmin.tra show -domain ${DomainName} -appspace ${AppSpaceName} applications"
 /opt1/tibco/tea/2.3/bin/bwadmin show -domain domains -appspace appspaces applications
 if [ "$DomainName" != 'ls' -a "$DomainName" != "-d" ]
 then
eval "${Command_To_Execute}"
  echo "a"
 else
  ""
 fi
done

答案1

我认为你需要首先格式化输出,并删除所有不需要的信息。考虑固定字段、关键字等等......

之后,您可以使用杰克转换为 JSON。我用它几次来编码/解码 JSON。

https://stedolan.github.io/jq/

相关内容