且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Azure-CLI Blob存储删除多个Blob

更新时间:2023-02-08 23:10:44

在我的测试中,您的脚本对我有用,也许我们可以尝试以下脚本:

In my test, your script works for me, maybe we can try this script:

export AZURE_STORAGE_ACCOUNT=jasontest321
export AZURE_STORAGE_ACCESS_KEY=+v6/ZQy74QhIwdvEMbnMV7HMaDaNUAkCDizBTOVdZkBUlw==
export container_name=vhds
for i in `az storage blob list --container-name $container_name --output table | awk '{print $1}'| sed '1,2d' | sed '/^$/d'` ; do
    if az storage blob delete --name $i --container-name $container_name >/dev/null ; then
      echo "Files $i inside the $container_name have been erased"
    else
      echo "Unable to erase the files $i inside the  $container_name." && exit 1
    fi
done

以下是有关结果的屏幕截图:

Here is the screenshot about the result:

更新:

#az --version
.
role (2.0.5)
sf (1.0.2)
sql (2.0.4)
storage (2.0.7)
vm (2.0.7)

Python (Linux) 2.7.5 (default, Nov  6 2016, 00:28:07) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)]

Python location '/root/lib/azure-cli/bin/python'
[root@jasoncli@jasonye ~]# python
Python 2.7.5 (default, Nov  6 2016, 00:28:07) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-11)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 

在我的实验室中,我的根帐户版本为2.7.5.我们应该为您的用户aruka检查您的python版本.

In my lab, my root account version is 2.7.5. we should check your python version for your user aruka.

Update2:
我们可以使用Azure门户云外壳来测试以下脚本:

Update2:
We can use Azure portal cloud shell to test this script:

Update3:

root@jasonvm:~# history
    1  echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ wheezy main" |      sudo tee /etc/apt/sources.list.d/azure-cli.list
    2  sudo apt-key adv --keyserver packages.microsoft.com --recv-keys 417A0893
    3  sudo apt-get install apt-transport-https
    4  sudo apt-get update && sudo apt-get install azure-cli
    5  export AZURE_STORAGE_ACCOUNT=jasondisk321
    6  export AZURE_STORAGE_ACCESS_KEY=O1/xxxWRzOlWep78iRcxxx/htgxHImKxxytlsv7gnn0hg1aGvw==
    7  export container_name=vhds
    8  for i in `az storage blob list --container-name $container_name --output table | awk '{print $1}'| sed '1,2d' | sed '/^$/d'` ; do     if az storage blob delete --name $i --container-name $container_name >/dev/null ; then       echo "Files $i inside the $container_name have been erased";     else       echo "Unable to erase the files $i inside the  $container_name." && exit 1;     fi; done
    9  az login -u jason.ye@xxxx.onmicrosoft.com -p xxxx
   10  export AZURE_STORAGE_ACCOUNT=jasondisk321
   11  export AZURE_STORAGE_ACCESS_KEY=O1/2D1UxeGcOlWep78iRcR5PxxgxxxzRbWoytlsv7gnn0hg1aGvw==
   12  export container_name=vhds
   13  for i in `az storage blob list --container-name $container_name --output table | awk '{print $1}'| sed '1,2d' | sed '/^$/d'` ; do     if az storage blob delete --name $i --container-name $container_name >/dev/null ; then       echo "Files $i inside the $container_name have been erased";     else       echo "Unable to erase the files $i inside the  $container_name." && exit 1;     fi; done
   14  export AZURE_STORAGE_ACCOUNT=jasondisk321
   15  export AZURE_STORAGE_ACCESS_KEY=O1/2D1UC0xxx/ztABmMyQFCeGcWRzOlWep78iRcR5Pt/K9yKxMT/htgxHImKqgznzRbWoytlsv7gnn0hg1aGvw==
   16  export container_name=vhds
   17  for i in `az storage blob list --container-name $container_name --output table | awk '{print $1}'| sed '1,2d' | sed '/^$/d'` ; do     if az storage blob delete --name $i --container-name $container_name >/dev/null ; then       echo "Files $i inside the $container_name have been erased";     else       echo "Unable to erase the files $i inside the  $container_name." && exit 1;     fi; done
   18  history