【问题标题】:bash script to ittarate trough files and push to s3bash脚本遍历文件并推送到s3
【发布时间】:2014-12-10 13:00:59
【问题描述】:

我有以下 bash 脚本:

s3upload() {
    n=$1
    extension=`file $n | cut -d ' ' -f2 | awk '{print tolower($0)}'` 
    mimetype=`file --mime-type $n | cut -d ' ' -f2`
    fullpath=`readlink -f $n`
    expires="Expires:`date -u +"%a, %d %b %Y %H:%M:%S GMT" --date "+1 years"`" 
    cache='Cache-Control:max-age=1296000, public'
    s3upload="s3cmd put -vvv --recursive setacl --acl-public --add-header $expires --add-header $cache -m $mimetype $fullpath s3://ccc-public/catalog/"  

    response=`$s3upload`
    echo $response
}
export -f s3upload
find nas/cdn/catalog/drawings/ \( ! -regex '.*/\..*' \) -type f | s3upload

当我执行它时,文件名不会被返回!

我喜欢让脚本检查每个文件的 mime-type 并设置过期和缓存。

如果我运行find nas/cdn/catalog/drawings/ \( ! -regex '.*/\..*' \) -type f,这将起作用并返回:

nas/cdn/catalog/drawings/N16.jpg
nas/cdn/catalog/drawings/EPB01.jpg
nas/cdn/catalog/drawings/N80.jpg
nas/cdn/catalog/drawings/EP22.jpg
nas/cdn/catalog/drawings/N95.jpg

非常感谢任何建议。

【问题讨论】:

    标签: bash amazon-s3 s3cmd


    【解决方案1】:

    尝试这样做:

    IFS=; while read -r file; do
      s3upload "$file"
    done <<< $(find nas/cdn/catalog/drawings/ \( ! -regex '.*/\..*' \) -type f)
    

    【讨论】:

      【解决方案2】:

      好的,我知道了

      expires="Expires:`date -u +"%a, %d %b %Y %H:%M:%S GMT" --date "+6 months"`"
      cache='Cache-Control:max-age=1296000, public'
      
      for f in $(find nas/cdn/catalog/drawings/ \( ! -regex '.*/\..*' \) -type f)
      do
          extension=`file $f | cut -d ' ' -f2 | awk '{print tolower($0)}'`
          mimetype=`file --mime-type $f | cut -d ' ' -f2`
          fullpath=`readlink -f $f`
          echo $expires
          #s3upload="s3cmd put -vvv --recursive setacl --acl-public --add-header $expires --add-header $cache -m $mimetype $fullpath s3://ccc-public/catalog/"
          #response=`$s3upload`
          #echo $response
      done
      

      【讨论】:

        猜你喜欢
        • 2016-02-08
        • 2021-05-31
        • 2018-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-01-16
        • 1970-01-01
        • 2011-05-11
        相关资源
        最近更新 更多