Skip to content

Instantly share code, notes, and snippets.

@abecciu
Created January 4, 2010 23:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abecciu/268982 to your computer and use it in GitHub Desktop.
Save abecciu/268982 to your computer and use it in GitHub Desktop.
#!/bin/bash
# this script requires the aws script from http://timkay.com/aws/
PATH="/bin:/usr/bin:/usr/sbin:/usr/local/bin"
LOCKFILE=/tmp/.s3logs.lock
QUEUEDIR=/var/spool/log-s3upload-queue
S3BUCKET=shopify-logs-bucket
enqueue() {
TAG=$1
FILE=`basename $2`
mkdir -p $QUEUEDIR
cp -f $2.1 $QUEUEDIR/`date '+%Y%m%d%H%M%S'`-$TAG-$FILE
}
upload() {
if [ -f $LOCKFILE ] ; then
exit 0
fi
touch $LOCKFILE
for f in `ls $QUEUEDIR` ; do
aws put $S3BUCKET/$f $QUEUEDIR/$f
if [ $? -eq 0 ] ; then
rm -f $QUEUEDIR/$f
fi
done
rm -f $LOCKFILE
}
usage() {
echo "usage: `basename $0` enqueue tag filename"
echo " `basename $0` upload"
exit 1
}
if [ $# -lt 1 ] ; then
usage
fi
if [ $1 == "enqueue" ] ; then
shift
enqueue $1 $2
elif [ $1 == "upload" ] ; then
shift
upload
else
usage
fi
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment