Skip to content

Instantly share code, notes, and snippets.

@watchamcb
Last active August 29, 2015 14:10
Show Gist options
  • Save watchamcb/5427d4e8a4ff287415b8 to your computer and use it in GitHub Desktop.
Save watchamcb/5427d4e8a4ff287415b8 to your computer and use it in GitHub Desktop.
Shell script to try and capture debug information for intermittent slow S3 uploads
#!/bin/bash
WORKING_DIR=/mnt/debug
UPLOAD_CMD="/usr/local/bin/s3cmd --debug put"
DELETE_CMD="/usr/local/bin/s3cmd del"
DEST_BUCKET=s3://your-bucket-name-here
cd $WORKING_DIR
TIMESTAMP=`date +%s`
#Generate test file for upload
dd if=/dev/zero of=upload.$TIMESTAMP bs=1M count=10 &> /dev/null
#Start tcpdump
sudo tcpdump -s 1024 -w $TIMESTAMP.pcap port 80 &> /dev/null &
#Perform upload
`/usr/bin/time -f %E $UPLOAD_CMD upload.$TIMESTAMP $DEST_BUCKET &> log.$TIMESTAMP`
# Get upload time in seconds (from last line of log file), probably a simpler way of doing this
UPLOAD_TIME=`tail -1 log.$TIMESTAMP | cut -d "." -f 1`
MINUTES=`echo $UPLOAD_TIME | cut -d ":" -f 1`
SECONDS=`echo $UPLOAD_TIME | cut -d ":" -f 2`
TOTAL_SECONDS=$(($MINUTES * 60 + $SECONDS))
# Cleanup
#Stop tcpdump
sudo fuser -s -k -TERM $TIMESTAMP.pcap
# Delete test upload file
rm upload.$TIMESTAMP
`$DELETE_CMD $DEST_BUCKET/upload.$TIMESTAMP &> /dev/null`
# Delete pcap if not a slow upload (save disk space)
if [ "$TOTAL_SECONDS" -lt 20 ]
then
rm -f $TIMESTAMP.pcap log.$TIMESTAMP
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment