Skip to content

Instantly share code, notes, and snippets.

@tmasjc
Last active December 10, 2018 05:07
Show Gist options
  • Save tmasjc/98c89b257701fbdace972bd944400f54 to your computer and use it in GitHub Desktop.
Save tmasjc/98c89b257701fbdace972bd944400f54 to your computer and use it in GitHub Desktop.
Queue item onto AWS S3. #aws #bash
#!/bin/bash
BUCKET="rdata"
if [[ -z $1 ]]; then
aws s3 ls s3://$BUCKET
elif [ $1 = "-u" ];
then
echo "Encrypting data..."
OBJ=$(ccrypt -e $2 -K "qwer" -f -q)
if [[ $? -eq 0 ]];
then
aws s3 cp "$2.cpt" s3://$BUCKET
fi
elif [ $1 = "-d" ];
then
LATEST=$(aws s3 ls s3://rdata | sort | tail -n 1 | awk '{print $4}')
echo "Downloading $LATEST into `pwd`..."
aws s3 cp s3://$BUCKET/$LATEST .
echo "Decrypting data..."
FILE=$(ccrypt -K "qwer" -d $LATEST)
if [[ $? -eq 0 ]];
then
echo "Success. Retrived one file, $LATEST."
fi
else
echo -e "Usage: rbucket \n upload, -u <filename> \n download, -d <filename>"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment