我正在为
query
运行 AWS aws fsx describe-file-systems
命令,我想组合两个运算符来查找 FileSystemType=="LUSTRE"
和另一个 Storagecapacity >1200
,然后使用查询来跟踪另一个内容。
为了获得结果,我尝试了以下命令,但出现错误:
aws fsx describe-file-systems --query "FileSystems[?FileSystemType=='LUSTRE' && Storagecapacity >1200 ] | reverse(sort_by(@, &LustreConfiguration.PerUnitStorageThroughput))[].{Name:Tags[?Key=='Name']|[0].Value, Storagecapacity:StorageCapacity, FS_ID:FileSystemId,Type:FileSystemType, Mount:LustreConfiguration.MountName, Throughput:LustreConfiguration.PerUnitStorageThroughput, Maintainancewindow:LustreConfiguration.WeeklyMaintenanceStartTime}" --profile demo --output table --no-cli-pager
上述命令产生的错误:
Bad value for --query FileSystems[?FileSystemType=='LUSTRE' && Storagecapacity >1200 ] | reverse(sort_by(@, &LustreConfiguration.PerUnitStorageThroughput))[].{Name:Tags[?Key=='Name']|[0].Value, Storagecapacity:StorageCapacity, FS_ID:FileSystemId,Type:FileSystemType, Mount:LustreConfiguration.MountName, Throughput:LustreConfiguration.PerUnitStorageThroughput, Maintainancewindow:LustreConfiguration.WeeklyMaintenanceStartTime}: invalid token: Parse error at column 58, token "1200" (NUMBER), for expression:
"FileSystems[?FileSystemType=='LUSTRE' && Storagecapacity >1200 ] | reverse(sort_by(@, &LustreConfiguration.PerUnitStorageThroughput))[].{Name:Tags[?Key=='Name']|[0].Value, Storagecapacity:StorageCapacity, FS_ID:FileSystemId,Type:FileSystemType, Mount:LustreConfiguration.MountName, Throughput:LustreConfiguration.PerUnitStorageThroughput, Maintainancewindow:LustreConfiguration.WeeklyMaintenanceStartTime}"
^
我自己的观察: 如果我应该查看上面的错误,它不喜欢与我提供的
int
值进行比较操作。
任何帮助将不胜感激。
在使用
json
数据类型时,很明显,适用于 Linux 和 macOS 的 AWS 您需要使用单引号 ' '
括起 JSON 数据结构并解释运算符值来按字面解释字符串。您需要使用命令替换(``)。
所以,如果您使用以下命令,它应该适合您......
$ aws fsx describe-file-systems --query 'FileSystems[?StorageCapacity >`12000` && FileSystemType==`LUSTRE`]|reverse(sort_by(@, &StorageCapacity))[].{Name:Tags[?Key==`Name`]|[0].Value,FileSystemType: FileSystemType, StorageCapacity: StorageCapacity, FS_ID:FileSystemId, Mount:LustreConfiguration.MountName, Throughput:LustreConfiguration.PerUnitStorageThroughput, Maintainancewindow:LustreConfiguration.WeeklyMaintenanceStartTime}' --profile demo --output table --no-cli-pager
现在,如果您查看上面的语法,就会发现完整的命令主体用单引号括起来
''
并且针对运算符的值位于命令替换中 (``)
IE 反引号,然后将其值正确扩展为想要的。
结果:
----------------------------------------------------------------------------------------------------------------------------------------------------
| DescribeFileSystems |
+----------------------+-----------------+---------------------+-----------+-------------------------------------+------------------+--------------+
| FS_ID | FileSystemType | Maintainancewindow | Mount | Name | StorageCapacity | Throughput |
+----------------------+-----------------+---------------------+-----------+-------------------------------------+------------------+--------------+
| fs-0200c83e16340020c| LUSTRE | 3:30:00 | gjiizbmv | labdemo-project1-00000001 | 271200 | 50 |
| fs-067d61e8fts63f99d| LUSTRE | 3:30:00 | s3a3fbmv | labdemo-project1-00000002 | 249600 | 200 |
| fs-01dg43bb9455b0011| LUSTRE | 3:30:00 | jg63fbmv | labdemo-project1-00000003 | 74400 | 50 |
+----------------------+-----------------+---------------------+-----------+-------------------------------------+------------------+--------------+