需求:多個帳號須要清空bucket。阿里不支持一鍵刪除,非常麻煩。bash
使用的工具是osscmd,先下載osscmd後解壓,而後在同級目錄建立兩個文件,一個寫AccessKeySecret,另外一個寫AccessKeyId,腳本以下。工具
#!/bin/bash #須要兩個文件,一個寫AccessKeySecret,另外一個寫AccessKeyId s=`cat AccessKeySecret |wc -l` for((z=1;z<=$s;z++)); do e=$z AccessKeySecret=`cat AccessKeySecret |sed -n "$e"p` AccessKeyId=`cat AccessKeyId |sed -n "$e"p` ./osscmd getallbucket --id=$AccessKeyId --key=$AccessKeySecret |grep -v CreateTime |grep -v Bucket |grep -v "^$" | awk '{print $4}' > a ./osscmd getallbucket --id=$AccessKeyId --key=$AccessKeySecret |grep -v CreateTime |grep -v Bucket |grep -v "^$" | awk '{print $3}' > b h=`cat a |wc -l` for((i=1;i<=$h;i++)); do n=$i #cat a |sed -n "$n"p > b project=`cat a |sed -n "$n"p` endpoint=`cat b |sed -n "$n"p` echo $project echo $endpoint #./osscmd deletewholebucket oss://$n --id=$AccessKeyId --key=$AccessKeySecret echo Y | ./osscmd deleteallobject oss://$project --host=$endpoint".aliyuncs.com" --force=on --id=$AccessKeyId --key=$AccessKeySecret echo Y | ./osscmd deletewholebucket oss://$project --host=$endpoint".aliyuncs.com" --force=on --id=$AccessKeyId --key=$AccessKeySecret done done