gpt4 book ai didi

AZ 存储 Blob 上的 Azure CLI IF 存在结果

转载 作者:行者123 更新时间:2023-12-02 07:37:59 24 4
gpt4 key购买 nike

我有一个通常可靠(但在一台服务器上很麻烦)的 Azure Blob 存储自动备份过程。如果由于某种原因上传失败,我希望我的 powershell 脚本能够重试上传。当 ABS 中尚不存在该文件时,我正在制作一个 if 语句(或 do while 循环)。如何捕获 AZ 的 Azure CLI 调用结果

我的测试尝试如下所示:

if(az storage blob exists --account-name test --container-name test --name $name --sas-token $sasToken){
Echo "This is true"
}
else{
Echo "This is false"
}

单独运行 Azure CLI 的输出是:

{
"exists": true
}

这些天我使用了太多语言,语法总是略有不同

最佳答案

在变量中捕获 Azure CLI 调用的结果,例如 $answer = az storage blob contains ...

从 JSON 转换后测试答案的“exists”属性

if (($answer | ConvertFrom-Json).exists) {
Write-Host "blob '$name' exists"
}
else {
Write-Host "No blob called '$name' was found"
}

关于AZ 存储 Blob 上的 Azure CLI IF 存在结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73639797/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com