Skip to content

Instantly share code, notes, and snippets.

@sheeplogh
Last active December 29, 2015 16:59
Show Gist options
  • Save sheeplogh/7701112 to your computer and use it in GitHub Desktop.
Save sheeplogh/7701112 to your computer and use it in GitHub Desktop.
count hits of some URLs per day from access_log
#!/bin/sh -e
TODAY=`date +%Y%m%d`
if [ $# -eq 1 ]
then
TARGET_DATE=$1
else
TARGET_DATE=`date -d "1 day ago" +%Y%m%d`
fi
echo -e "DATE\t\tURL1\tURL2"
while [ "${TARGET_DATE}" != "${TODAY}" ]
do
echo -e "\
`date -d ${TARGET_DATE} +%Y/%m/%d`\t\
`zcat /var/log/httpd/example.com/access_log.${TARGET_DATE}.gz | grep URL1 | wc -l`\t\t\
`zcat /var/log/httpd/example.com/access_log.${TARGET_DATE}.gz | grep URL2 | wc -l`\
"
TARGET_DATE=`date -d "${TARGET_DATE} 1 day" +%Y%m%d`
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment