首页 > 解决方案 > 我正在编写一个 bash 脚本,但我被困在使用“jq”命令进行管道传输的地方

问题描述

我的输入 JSON:

{
    "PendingMaintenanceActions": [
        {
            "ResourceIdentifier": "arn:aws:rds:xxxxxx1230000345",
            "PendingMaintenanceActionDetails": [
                {
                    "Action": "hardware-maintenance",
                    "AutoAppliedAfterDate": "2020-12-17T08:00:00Z",
                    "ForcedApplyDate": "2020-12-18T13:00:00Z",
                    "CurrentApplyDate": "2020-12-17T08:00:00Z",
                    "Description": "Maintenance on the underlying hardware"
                }
            ]
        }
    ]
}

所需输出:

arn:aws:rds:xxxxxx1230000345,hardware-maintenance,2020-12-17T08:00:00Z,Maintenance on the underlying hardware

我尝试了很多,但没有运气。有人可以帮我获得所需的输出。

谢谢你。

标签: bashshelljqaws-cli

解决方案


aws rds ... | jq '.PendingMaintenanceActions[].ResourceIdentifier + "," + .PendingMaintenanceActions[].PendingMaintenanceActionDetails[].Action + "," + .PendingMaintenanceActions[].PendingMaintenanceActionDetails[].CurrentApplyDate + "," + .PendingMaintenanceActions[].PendingMaintenanceActionDetails[].Description'

不确定需要哪个日期,但 CurrentApplyDate 可以根据需要更改


推荐阅读