閱讀99 返回首頁    go 微信


查詢指定區域下所有實例 ID 並輸出到文件__腳本使用示例_用戶指南_命令行工具 CLI-阿裏雲

您可以利用命令行工具,通過如下腳本,查詢指定區域下所有實例 ID 並輸出到文件。您可選擇下載腳本或編輯腳本內容。

點擊下載腳本:getVmList.zip

腳本內容如下:

  1. #!/bin/bash
  2. tcount=`aliyuncli ecs DescribeInstances --RegionId $1 --output json --filter TotalCount`
  3. pageNum=1
  4. cat /dev/null >vmList.txt
  5. while ((tcount>0))
  6. do
  7. aliyuncli ecs DescribeInstances --RegionId $1 --PageSize 100 --PageNumber $pageNum --output json --filter Instances.Instance[*].InstanceId | sed '1d' | sed '$d' | sed 's/,//g' | sed 's/"//g'| sed 's/ //g'>>vmList.txt
  8. let pageNum++
  9. let tcount-=100
  10. done
  11. cat vmList.txt

編輯或下載腳本並賦權(chmod +x)後,您通過如下格式執行,即會在腳本所在目錄下生成包含所需實例 ID 的文件 vmList.txt。

使用格式說明:

  1. ./getVmList.sh <區域 ID>

注意:區域 ID 可以通過 DescribeRegions 接口獲取。

用法示例:

  1. ./getVmList.sh cn-hangzhou

輸出示例:

  1. #./getVmList.sh cn-hangzhou
  2. cn-hangzhou sg-227f611ss
  3. cn-hangzhou sg-22esa2s7s

最後更新:2016-11-23 16:04:16

  上一篇:go 查詢已訂閱的鏡像市場鏡像信息__腳本使用示例_用戶指南_命令行工具 CLI-阿裏雲
  下一篇:go 查詢所有區域下未創建任何 VSwitch 的 VPC 列表__腳本使用示例_用戶指南_命令行工具 CLI-阿裏雲