如何动态捕获AWS EC2实例IP?

时间:2015-10-15 00:11:17

标签: amazon-web-services awk sed amazon-ec2

如果每次都随机自动生成,如何捕获少量echo "$(curl http://169.254.169.254/latest/meta-data/public-ipv4/) master" >> /etc/hosts 实例IP并将它们放到脚本变量中? 我试图用

来做到这一点
aws ec2

但它只是其中一个的IP。 也在尝试 awk describe-instances ... 但不知道如何将明确的IP与其他信息分开。有sed \ <script src="js/jquery-1.8.3.min.js" type="text/javascript"></script> <script type="text/javascript"> $(document).ready(function() { $.ajax({ type: "get", url: "region_action2.php", data: {"parent_id": "1", "type": "1"}, dataType: "json", success: function(data) { $.each(data, function(i, item) { **// $("#provinces select").val(17); //does not work** **$('#provinces option[value=17]').attr('selected','selected'); //works but #citys valus did not show.** $("#provinces").append("<option value='" + item.id + "'>" + item.english + "</option>"); }); } }); $("#provinces").change(function() { $.ajax({ type: "get", url: "region_action2.php", data: {"parent_id": $(this).val(), "type": "2"}, dataType: "json", success: function(data) { //$("#citys").html("<option value=''>Select Postcode</option>"); $.each(data, function(i, item) { //$('#citys option[value=12543]').attr('selected','selected'); $("#citys").append("<option value='" + item.id + "'>" + item.english + "</option>"); }); } }); }); ... </script> <div> State: <select name="trop_1_id" id="provinces"> <option value="" >Select State2</option> </select> Postcode: <select name="trop_2_id" id="citys"> <option value="">Select Postcode</option> </select> Suburb: ... </div> 的任何建议吗?

3 个答案:

答案 0 :(得分:2)

AWS Command-Line Interface (CLI)--query参数一起使用:

aws ec2 describe-instances --query 'Reservations[*].Instances[*].{ID:InstanceId,Public:PublicIpAddress,Private:PrivateIpAddress}' --output text
i-2da518a2  172.31.15.3 None
i-6d261640  172.31.27.232   56.64.218.82
i-b3aa3476  172.31.5.0  None
i-6c57c951  172.31.20.243   56.79.129.118
i-192b95c1  172.31.28.76    56.253.207.57
i-af413c91  172.31.27.17    None

您还可以输出JSON,这更容易解析。

答案 1 :(得分:0)

结束命令是

class Parent1
{
    static $db = null;

    public function __construct()
    {
        self::$db = 'a';
    }
}

class Child extends Parent1
{

    public function __construct()
    {
        parent::__construct();
        self::$db = 'b';
    }
}

$myParent = new Parent1();
echo $myParent::$db; //"a"

$myChild = new Child();
echo $myChild::$db; //"b"
echo $myParent::$db; //"b" it should be "a"

使用标记从aws实例捕获动态ip地址并将其放入任何文件

答案 2 :(得分:0)

例如,如果您想获取负载均衡器后面的所有私有IP并将其传递给文件。

/ usr / bin / aws --output text --query“Reservations []。Instances []。PrivateIpAddress”ec2 describe-instances --instance-ids aws --output text --query "LoadBalancerDescriptions[0].Instances[*].InstanceId" elb describe-load-balancers --load-balancer-name <loadbalancer name>&gt; HOSTS.TXT

希望它有所帮助......