0

i have the following bash script:

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

when i execute it the file names are not returned!

i like for the script to check each file mime-type and set the expiry and cache.

if i run find nas/cdn/catalog/drawings/ \( ! -regex '.*/\..*' \) -type f this works and returns:

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

any advice much appreciated.

khinester
  • 3,398
  • 9
  • 45
  • 88

2 Answers2

0

ok, i figured it out

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
khinester
  • 3,398
  • 9
  • 45
  • 88
0

Try doing it this way:

IFS=; while read -r file; do
  s3upload "$file"
done <<< $(find nas/cdn/catalog/drawings/ \( ! -regex '.*/\..*' \) -type f)
arco444
  • 22,002
  • 12
  • 63
  • 67