953
微信
查询所有地域下未关联任何实例的安全组 ID__脚本使用示例_用户指南_命令行工具 CLI-阿里云
您可以利用命令行工具,通过如下脚本,查询所有区域下未关联任何实例的安全组,然后进行删除等处理。您可选择下载脚本或编辑脚本内容。
点击下载脚本:getUnUsedSecurityGroupId.zip
脚本内容如下:
#!/bin/bash
for RegionId in `aliyuncli ecs DescribeRegions --filter Regions.Region[*].RegionId --output json | sed '1d' | sed '$d' | sed 's/,//g' | sed 's/"//g'| sed 's/ //g'`
do
cat /dev/null >/tmp/UnUsedSecurityGroupIds.txt
pageNum=1
tcount=`aliyuncli ecs DescribeSecurityGroups --RegionId $RegionId --output json --filter TotalCount`
while ((tcount>0))
do
aliyuncli ecs DescribeSecurityGroups --RegionId $RegionId --filter SecurityGroups.SecurityGroup[*].SecurityGroupId --PageSize 100 --PageNumber $pageNum --output json | sed '1d' | sed '$d' | sed 's/,//g' | sed 's/"//g'| sed 's/ //g'>>/tmp/UnUsedSecurityGroupIds.txt
let pageNum++
let tcount-=100
done
cat /tmp/UnUsedSecurityGroupIds.txt | while read line
do
usedVMCount=`aliyuncli ecs DescribeInstances --RegionId $RegionId --SecurityGroupId $line --output json --filter TotalCount`
if [[ $usedVMCount -eq 0 ]];then
echo $RegionId " " $line
fi
done
done
编辑或下载脚本并赋权(chmod +x)后,您可以通过如下格式直接执行脚本,即会按地域和安全组成对输出所有地域下未使用的安全组 ID。
使用格式说明:
./getUnUsedSGInfo.sh
输出示例:
[root@AliyunTest]# ./getUnUsedSGInfo.sh
cn-qingdao sg-227f61lts
cn-shenzhen sg-22esa0f7s
最后更新:2016-11-23 16:04:16
上一篇:
查询所有区域下未创建任何 VSwitch 的 VPC 列表__脚本使用示例_用户指南_命令行工具 CLI-阿里云
下一篇:
使用在线帮助__命令行结构和参数_用户指南_命令行工具 CLI-阿里云
Python教程__sdk_数据风控-阿里云
查看慢日志列表__日志管理_API 参考_云数据库 RDS 版-阿里云
阿里云数据集成__数据传输软件_开发人员指南_E-MapReduce-阿里云
配置后端 ECS 实例__快速入门_负载均衡-阿里云
发布版本__产品简介_业务实时监控服务 ARMS-阿里云
协同过滤做商品推荐__案例_机器学习-阿里云
功能示例__文字识别_人工智能图像类-阿里云
2.4 ECU详解__第二章 基本概念_使用手册_分析型数据库-阿里云
修改RDS实例访问模式__实例管理_API 参考_云数据库 RDS 版-阿里云
效果报表__用户指南_推荐引擎-阿里云
相关内容
常见错误说明__附录_大数据计算服务-阿里云
发送短信接口__API使用手册_短信服务-阿里云
接口文档__Android_安全组件教程_移动安全-阿里云
运营商错误码(联通)__常见问题_短信服务-阿里云
设置短信模板__使用手册_短信服务-阿里云
OSS 权限问题及排查__常见错误及排除_最佳实践_对象存储 OSS-阿里云
消息通知__操作指南_批量计算-阿里云
设备端快速接入(MQTT)__快速开始_阿里云物联网套件-阿里云
查询API调用流量数据__API管理相关接口_API_API 网关-阿里云
使用STS访问__JavaScript-SDK_SDK 参考_对象存储 OSS-阿里云