aws
命令行工具,但不知道如何在shell脚本中使用它。当我运行命令
aws s3 ls s3://bucket
时,会得到以下结果:
这意味着指定的存储桶不存在。因此,我想从shell脚本中运行该命令,并通过A client error (NoSuchBucket) occurred when calling the ListObjects operation: The specified bucket does not exist
grep
查找是否存在。但我的命令无法正常工作。if [ $(aws s3 ls "s3://$S3_BUCKET" | grep 'NoSuchBucket' &> /dev/null) == 0 ]
then
echo "$S3_BUCKET doesn\'t exist please check again"
exit
fi
它只是给了我这个
备份.sh: 20: [: 0: 意外的操作符
更新
我将脚本更改为
echo "S3_BUCKET=$S3_BUCKET"
if aws s3 ls "s3://$S3_BUCKET" | grep -q 'AllAccessDisabled'
then
echo "$S3_BUCKET doesn\'t exist please check again"
exit
fi
这是我得到的输出结果
A client error (AllAccessDisabled) occurred when calling the ListObjects operation: All access to this object has been disabled
文本中包含 AllAccessDisabled
,但我仍然无法echo
下一行。