0

Using this format I need to write a bash script where I can pass Bucketname and FilesNames as text files and it would run it as BucketName1/File1,File2.. FileN BucketName1/File1,File2.... FileN

Below is what I have written. But I am not getting the required Output.

#!/bin/bash
BucketName=$1
FileName=$2
while IFS= read -r FileName
do
aws s3 cp s3://${BucketName}/${FileName} .
done

1 Answers1

0

If the second argument points to the file with list of files to download, then the following should work:

#!/bin/bash
BucketName=$1
FileName=$2
while IFS= read -r file;
#while IFS= read -r FileName
do
aws s3 cp s3://$BucketName/$file .
done < $FileName

Where the second argument is a file like:

file1.csv
file2.csv
file3.csv

Output:

$ bash s3bash.sh mybucket s3files.txt
download: s3://mybucket/file1.csv to ./file1.csv         
download: s3://mybucket/file2.csv to ./file2.csv         
download: s3://mybucket/file3.csv to ./file3.csv         

If you are passing the list of files as a delimited string, instead of the file - check this answer: https://stackoverflow.com/a/27703327/5535604

Anton
  • 3,587
  • 2
  • 12
  • 27