Skip to content

Instantly share code, notes, and snippets.

@PauloMigAlmeida
Created July 28, 2015 20:57
Show Gist options
  • Save PauloMigAlmeida/4f4d998c94cc95db40f1 to your computer and use it in GitHub Desktop.
Save PauloMigAlmeida/4f4d998c94cc95db40f1 to your computer and use it in GitHub Desktop.
Downlads today's files from a AWS S3 bucket
#/bin/bash
# Usage ./download.sh <bucket_name> <target_folder>
# Example: ./download.sh test ./files_today
# Note: you must configure your awscli before use this. Execute aws configure
BUCKET_NAME=$1
TARGET_DIR=$2
FILES_LIST=$TARGET_DIR/files.txt
aws s3 ls s3://$BUCKET_NAME | grep $(date +'%Y-%m-%d') | awk '{ print $4 }' > $FILES_LIST
while IFS= read -r line || [ -n "$line" ]; do
aws s3 cp s3://$BUCKET_NAME/$line $TARGET_DIR/
done <$FILES_LIST
rm -f $FILES_LIST
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment