阿里云,批量删除oss所有的bucket
需求:多个账号需要清空bucket。阿里不支持一键删除,很是麻烦。
使用的工具是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
写文不易,转载请注明出处