1

是否有任何命令/工具/脚本可以对ec2-describe-imagesor的庞大输出进行分类ec2-describe-instances

我有一个大约 100 台服务器的列表,其中包含每一个细节。我想将它们分类在合适的标题下,例如 - RESERVATION, INSTANCE, BLOCKDEVICE, TAG(输出中可用的任何类别)。

4

3 回答 3

1

你整理好了吗?如果不...

运行带有选项--headers的 ec2-describe-images为您提供类别

ec2-describe-images --private-key ~/private.key --cert ~/my.crt --region us-west-1 --headers

如果您只想要某些字段,那么只需通过 linux 命令cut选择您所追求的字段(列)来传递上述输出。假设您想要 ImageID、Name 和 Architecture,那么这些将是上面输出的字段 2,3 和 8。例子。

 ec2-describe-images --private-key ~/private.key --cert ~/my.crt --region us-west-1 --headers | cut -f2,3,8 -s

对 ec2-describe-instances 执行相同操作将是类似的。

于 2012-05-06T09:51:33.813 回答
0

这是awk(或perlpython或其他通用脚本语言)的工作。

awk可以处理各种记录/字段长度的记录,可以创建关联数组,它是一种报告语言,通常安装在每个 *nix 上。

于 2012-01-15T20:50:03.340 回答
0

将此添加到您的 ~/.bashrc 或 ~/.bash_profile:

ez-ec2-describe-instances() {
    ec2-describe-instances $* --headers | egrep '(ReservationID|running|pending)'|cut -f 2,3,4,6,7,10,12; 
}

注销/登录或运行“.~/.bashrc”。然后你可以使用:

$ ez-ec2-describe-instances 
ReservationID   Owner   Groups
i-6f194113  ami-1624987f    ec2-107-20-75-13.compute-1.amazonaws.com    running t1.micro    us-east-1a

您可以将参数传递给 ez-ec2-describe-instances,就像将它们传递给常规的 ec2-describe-instances 一样。例如:

$ ez-ec2-describe-instances --region eu-west-1
ReservationID   Owner   Groups
i-e4fd6eaf  ami-c37474b7    ec2-54-246-38-35.eu-west-1.compute.amazonaws.com    pending t1.micro    eu-west-1a
于 2012-11-04T00:10:56.597 回答