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",
         },

誰でもこの問題を解決するのに役立ちますか?

以下は私が使用するコードです。これはループにあるので、1つずつ出力を取得します。問題は、他の場所で使用するために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/

おすすめ記事