如何在 shell 脚本中获取 ec2-describe-instances 的标签 [英] How to fetch the tags for ec2-describe-instances in a shell script

查看:23
本文介绍了如何在 shell 脚本中获取 ec2-describe-instances 的标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从命令 ec2-describe-instances 的结果中提取实例 ID 和标签,并将结果存储在文本文件中.结果集给出:

I want to extract the instance ID and the tags from the result of a command ec2-describe-instances and want to store the result in a text file. The result set gives :

但我希望标签所有者和 cost.centre 也能被获取请指导我如何做到这一点

But i want the tags owner and cost.centre also to be fetched Kindly guide me how to do that

推荐答案

这是另一种不使用 jq 和其他解析工具的方法.

Here is another way to do without using jq and other parsing tools.

ec2 describe-instances --query 'Reservations[*].Instances[*].[InstanceId,Tags[?Key==`Name`].Value | [0],Tags[?Key==`cost.centre`].Value | [0]]' --output text

这篇关于如何在 shell 脚本中获取 ec2-describe-instances 的标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆