Select files on S3 since a certain date in bash
I would like to select all files on a S3 folder that have been created since a certain date. I can do that by:
Code:
aws s3 ls --recursive s3://my-s3-folder/ | awk '$1 > "2015-11-03 15:46:37" {print $0}' | sort -n Code:
function select_s3_files() { Code:
awk: > $prev_run_date {print ./cp-s3-folder.sh} |
Quote:
Quote:
did you notice that the code is not the same?, the quote Code:
' Code:
$AWS_BIN s3 ls --recursive $S3_FOLDER | awk '$1 > "$prev_run_date" {print '$0'}' | sort -n M. |
Your modification doesn't throw any error, but it doesn't filter the output files. It shows all files and not only the files that have been modified since that date.
When I echo the command Code:
echo "$AWS_BIN s3 ls --recursive $S3_FOLDER | awk '$1 > "$prev_run_date" {print '$4'}' | sort -n" Code:
/usr/local/bin/aws s3 ls --recursive s3://my-folder/archive/ | awk ' > 2015-11-03 15:46:37 {print ''}' | sort -n |
I like using find in conjunction with a temporary file to do this.
Code:
touch -t 201511031546.37 /tmp/last |
I cannot use find in aws S3. The find command is not supported.
It's working perfect in command line, but I'm struggling to get it to work in a bash script with the different $1 and $4 variables and all the different ' " quotes. |
You can't (easily) use bash variables like that in awk - pass them in as assigned awk variables using "-v"
Code:
awk -v prev="$prev_run_date" '$1 > prev {print $4}' |
you could mount the bucket using sshfs and then use find on that mount.
|
[SOLVED]
Thanks for the replies. I've solved it by Code:
function select_s3_files() { |
Good job and well done.
Glad it worked out! |
Quote:
|
Hmmm - I did warn about that some months ago.
|
All times are GMT -5. The time now is 12:47 AM. |