AWS S3:如何使用bash检查存储桶中是否存在文件
我想知道是否可以检查某个存储桶中是否存在某些文件.
这是我发现的: Checking if a file is in a S3 bucket using the s3cmd
Summary of all the methods that can be used in the Amazon S3 web service
他们是否希望您创建一个布尔变量来保存方法的状态,或者该函数是否直接给出输出/抛出错误? 这是我目前在我的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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |