AWS S3:如何使用bash检查存储桶中是否存在文件

前端之家收集整理的这篇文章主要介绍了AWS S3:如何使用bash检查存储桶中是否存在文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想知道是否可以检查某个存储桶中是否存在某些文件.

这是我发现的:

Checking if a file is in a S3 bucket using the s3cmd

It should fix my problem,but for some reason it keeps returning that the file doesn’t exist,while it does. This solution is also a little dated and doesn’t use the doesObjectExist method.

Summary of all the methods that can be used in the Amazon S3 web service

This gives the Syntax of how to use this method,but I can’t seem to make it work.

他们是否希望您创建一个布尔变量来保存方法的状态,或者该函数是否直接给出输出/抛出错误

这是我目前在我的bash脚本中使用的代码

existBool=doesObjectExist(${BucketName},backup_${DomainName}_${CurrentDate}.zip)

if $existBool ; then
        echo 'No worries,the file exists.'
fi

我只使用文件名来测试它,而不是给出完整路径.但由于我得到的错误是语法错误,我可能只是错误地使用它.

希望有人可以帮助我,告诉我我做错了什么.

!编辑

我最终寻找另一种方法来做到这一点,因为使用doesObjectExist不是最快或最简单的.

一种简单的方法是使用aws s3 ls
exists=$(aws s3 ls $path_to_file)
if [ -z "$exists" ]; then
  echo "it does not exist"
else
  echo "it exists"
fi
原文链接:https://www.f2er.com/bash/383512.html

猜你在找的Bash相关文章