edit-icon download-icon

Query the VPC instance ID list with no VSwitch created in all regions

Last Updated: Dec 21, 2017

You can run the following script in Alibaba Cloud CLI to query the VPC instance ID list with no VSwitch created in all regions. You can download or edit the script.

Click to download the script: getNoVSWitchVpcIds.zip.

The script is as follows:

  1. #!/bin/bash
  2. 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'`
  3. do
  4. cat /dev/null >/tmp/vpcIDs.txt
  5. pageNum=1
  6. tcount=`aliyuncli ecs DescribeVpcs --RegionId $RegionId --output json --filter TotalCount`
  7. while ((tcount>0))
  8. do
  9. aliyuncli ecs DescribeVpcs --RegionId $RegionId --filter Vpcs.Vpc[*].VpcId --PageSize 50 --PageNumber $pageNum --output json | sed '1d' | sed '$d' | sed 's/,//g' | sed 's/"//g'| sed 's/ //g'>>/tmp/vpcIDs.txt
  10. let pageNum++
  11. let tcount-=50
  12. done
  13. cat /tmp/vpcIDs.txt | while read line
  14. do
  15. vSwitchCount=`aliyuncli ecs DescribeVSwitches --VpcId $line --output json --filter TotalCount`
  16. if [[ $vSwitchCount -eq 0 ]];then
  17. echo $RegionId $line
  18. fi
  19. done
  20. done

After editing or downloading the script and granting the permission (by running the chmod + x command), you can run the script in the following format to export the VPC instance IDs (in pairs) with no VSwitch created in all regions in the Region ID VpcId format by region.

Format:

  1. ./getNoVSWitchVpcIds.sh

Sample output:

  1. [root@AliyunTest]# ./getNoVSWitchVpcIds.sh
  2. cn-hangzhou vpc-23vyarrss
Thank you! We've received your feedback.