从命令行设置 Amazon EC2 实例列表的格式

发布于 2024-11-20 00:02:54 字数 584 浏览 6 评论 0原文

我使用 ec2-describe-instances -H 检索有关当前 Amazon EC2 实例的数据,它返回如下内容:

Type    ReservationID   Owner   Groups  Platform
RESERVATION r-xxxxxxxx  xxxxxxxxxxxx    default
INSTANCE    i-xxxxxxxx  ami-2b5fba42    ec2-xx-xx-xx-xx.compute-1.amazonaws.com ip-xx-xx-xx-xx.ec2.internal running user    0       m1.small    2011-07-12T21:15:39+0000    us-east-1a  aki-xxxxxxxx    ari-xxxxxxxx        monitoring-disabled xx.xx.xx.xx xx.xx.xx.xx         instance-store          paravirtual xen     sg-xxxxxxxx default

这在 OS X 终端中看起来很混乱。我怎样才能使这个输出更具可读性?

I retrieve data about my current Amazon EC2 instances with ec2-describe-instances -H, which returns something like the following:

Type    ReservationID   Owner   Groups  Platform
RESERVATION r-xxxxxxxx  xxxxxxxxxxxx    default
INSTANCE    i-xxxxxxxx  ami-2b5fba42    ec2-xx-xx-xx-xx.compute-1.amazonaws.com ip-xx-xx-xx-xx.ec2.internal running user    0       m1.small    2011-07-12T21:15:39+0000    us-east-1a  aki-xxxxxxxx    ari-xxxxxxxx        monitoring-disabled xx.xx.xx.xx xx.xx.xx.xx         instance-store          paravirtual xen     sg-xxxxxxxx default

This looks messy in the OS X terminal. How can I make this output more readable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江城子 2024-11-27 00:02:54

我刚刚编写了一些您可能感兴趣的 bash/awk 脚本:

https://github.com/epheph/fec2din

它以以下格式显示 EC2 实例输出:

Instance: i-57192e11
AMI: ami-a7f539ce
Type: t1.micro
Public IP: 50.99.41.60 (ec2-50-99-41-60.compute-1.amazonaws.com)
Private IP: 10.99.241.197
Public Key: production
Start Time: 2011-11-09
Security Group: production
Block Devices:
    /dev/sda1
    /dev/sdj
    /dev/sdk

I just whipped up a little bash/awk script you might be interested in:

https://github.com/epheph/fec2din

It displays EC2 instance output in the format of:

Instance: i-57192e11
AMI: ami-a7f539ce
Type: t1.micro
Public IP: 50.99.41.60 (ec2-50-99-41-60.compute-1.amazonaws.com)
Private IP: 10.99.241.197
Public Key: production
Start Time: 2011-11-09
Security Group: production
Block Devices:
    /dev/sda1
    /dev/sdj
    /dev/sdk
北方。的韩爷 2024-11-27 00:02:54

您想看到或查看哪些具体部分?

 ec2-describe-instances | grep INSTANCE | awk {'print $4'}

这将为您提供实例名称,在您的示例中为 ec2-xx-xx-xx-xx.compute-1.amazonaws.com

编辑

正如提出问题的人所说,他们希望以更干净的格式......没有具体说明那是什么......这是我微弱的尝试:

 #!/bin/bash

 tmpFile="/tmp/ec2.info"
 ec2Info=`ec2-describe-instances > $tmpFile`
 instances=`cat $tmpFile | grep TAG | awk {'print $3'}`
 numOfInstances=`cat $tmpFile | grep INSTANCE | wc -l`
 you=`whoami`


 echo "Dear $you, I wanted to describe for you the current number of instances you have: $numOfInstances"
 echo "The instances you have, by hostname, are as follows ..."
 for instance in $instances
 do
      hostname=`cat $tmpFile | grep INSTANCE | grep $instance | awk {' print $4 '}`
      echo "$hostname"
 done

小免责声明上面的代码可能并不完美......它是为了向提出问题的人提供正确的信息,以制作他们认为合适的“干净格式”。

What specific portions would you like to see, or view?

 ec2-describe-instances | grep INSTANCE | awk {'print $4'}

This will give you the instance name, which would be ec2-xx-xx-xx-xx.compute-1.amazonaws.com in your example.

Edit

As the person asking the question said they wanted it in a cleaner format ... without specifying what that is ... here is my feeble attempt:

 #!/bin/bash

 tmpFile="/tmp/ec2.info"
 ec2Info=`ec2-describe-instances > $tmpFile`
 instances=`cat $tmpFile | grep TAG | awk {'print $3'}`
 numOfInstances=`cat $tmpFile | grep INSTANCE | wc -l`
 you=`whoami`


 echo "Dear $you, I wanted to describe for you the current number of instances you have: $numOfInstances"
 echo "The instances you have, by hostname, are as follows ..."
 for instance in $instances
 do
      hostname=`cat $tmpFile | grep INSTANCE | grep $instance | awk {' print $4 '}`
      echo "$hostname"
 done

small disclaimer the above code may not be perfect ... it's to give the person asking the question the right information to make a "clean format" however they see fit.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文