【问题标题】:AWS CLI S3 Sync exclude not working in script, directly in terminal it doesAWS CLI S3 Sync 排除在脚本中不起作用,直接在终端中起作用
【发布时间】:2018-11-08 13:58:35
【问题描述】:

我正在尝试创建一个 shell 脚本来管理我与 s3 存储桶的同步。 这是我的脚本中的内容:

#!/bin/bash

aws s3 sync $1 $2 $(for word in $(echo "$excludeconf"| tr ";" " "); do echo -n "--exclude \"$word\" "; done) $del --no-follow-symlinks $3

$1 是来源 $2 是目的地 $3 是另一个被传递的参数(dryrun)。 $(word... 获取文件和文件夹列表$excludeconf 并使用它们创建--exclude ...

如果我运行脚本,它不会排除任何内容。

如果我在上面的命令前面加上echo,我会得到:

aws s3 sync . s3://BUCKETNAME/FOLDERNAME/ --exclude .SOMEFILE --exclude "public/icon/*" --delete --no-follow-symlinks --dryrun

如果我复制该命令并在终端中手动运行它,它就可以正常工作。

有什么想法吗?

仅供参考:我正在运行 CentOS 7

编辑:

经过一些测试,我发现问题出在通配符上:public/icon/* 被解释为 public/icon/folder1 public/icon/folder2 如果我尝试设置 noglob,它将不起作用.. ist 因为它在 $(..) 里面吗?

【问题讨论】:

  • 脚本不工作时如何运行?在这种情况下,点可能会有不同的解释。
  • 我添加了它(#!/bin/bash)
  • 好的,但是它是如何执行的。定时任务?
  • 添加一个--debug 参数,看看它说了什么。 (你可能想删除--dryrun
  • 这个基本是stackoverflow.com/questions/12136948/…,解决方法一样:使用数组。

标签: shell amazon-s3 centos sh aws-cli


【解决方案1】:

我用python重写了脚本,改成:

os.system("set -f noglob && aws s3.....")

成功了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-30
    • 2020-12-14
    • 2011-10-14
    • 2020-03-21
    • 1970-01-01
    • 2016-11-12
    • 1970-01-01
    相关资源
    最近更新 更多