Skip to content

Instantly share code, notes, and snippets.

@bageljp
Last active October 9, 2019 21:59
Show Gist options
  • Save bageljp/5186820 to your computer and use it in GitHub Desktop.
Save bageljp/5186820 to your computer and use it in GitHub Desktop.
access_log parse.
#!/bin/bash
LOG_FILE="access_log-20130310"
for i in `seq 4 1 23`; do
hour=`printf "%02d" ${i}`
# sourceIp
grep "09/Mar/2013:${hour}" ${LOG_FILE} | awk '{print $1}' | sort | uniq -c | sort -r > ip-${hour}.log
# url
grep "09/Mar/2013:${hour}" ${LOG_FILE} | awk '{print $7}' | sort | uniq -c | sort -r > url-${hour}.log
# referer
grep "09/Mar/2013:${hour}" ${LOG_FILE} | awk '{print $10}' | sort | uniq -c | sort -r > referer-${hour}.log
# status
grep "09/Mar/2013:${hour}" ${LOG_FILE} | awk '{print $9}' | sort | uniq -c | sort -r > status-${hour}.log
done
#!/bin/bash
sum=0
while read line; do
i=`echo ${line} | awk '{print $1}'`
sum=$((${sum}+${i}))
done < $1
echo $sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment