加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-16 01:36:51 所属栏目:安全 来源:网络整理
导读:我想知道是否可以检查某个存储桶中是否存在某些文件. 这是我发现的: 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
我想知道是否可以检查某个存储桶中是否存在某些文件.

这是我发现的:

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读