Skip to content

Instantly share code, notes, and snippets.

@hsiboy
Created May 6, 2014 10:46
Show Gist options
  • Save hsiboy/61ff5bc38a9685c9c5d0 to your computer and use it in GitHub Desktop.
Save hsiboy/61ff5bc38a9685c9c5d0 to your computer and use it in GitHub Desktop.
prepare IIS W3C log files for use by siege - concatenate cs-uri-stem and the cs-uri-query
#!/bin/bash
# make sure you always put $f in double quotes to avoid any nasty surprises i.e. "$f"
for f in $@
do
if [ ! -f $f ];
then
echo "File ($f) not found!"
exit 0
fi
echo "Processing $f..."
# dos 2 unix, remove comments and empty lines
sed -i -e 's/.$//' -e 's/#.*//' -e '/^$/ d' "$f"
echo " Extracting URI and Query String..."
cut -d' ' -f6-8 "$f" > method_uri
#strip out load balancer check
grep -v "/load/balancer/check.HTML" method_uri > urls
rm method_uri
#i only want GETs
grep "GET" urls > urls.txt
rm urls
echo " Adding hostname..."
sed -i -e 's/GET /http:\/\/target.domain.com/' urls.txt
echo " Fixing up uri stem..."
# clear empty cs-uri-query fields
sed -i -e '1,/^ -/s/ -$//' urls.txt
# put '?' between the cs-uri-stem and the cs-uri-query
sed -i -e 's/ /?/' urls.txt
echo " Setting dates in cs-uri-query to `date +%Y-%m-%d`"
# update dates in cs-uri to today
sed -i -e 's/sDate=[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\}/sDate='`date +%Y-%m-%d`'/g' urls.txt
echo " Splitting load into 100,000 lines..."
split -l 100000 urls.txt SiegeUrls.
rm urls.txt
echo " Ready for Siege!"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment