Skip to content

Instantly share code, notes, and snippets.

@i97506051502
Created November 5, 2012 06:32
Show Gist options
  • Save i97506051502/4015672 to your computer and use it in GitHub Desktop.
Save i97506051502/4015672 to your computer and use it in GitHub Desktop.
combined 形式アクセスログファイルの解析
#!/bin/bash
Date="$1"
# アクセス元 IP アドレスの数
cut -d ' ' -f 1 access_log-${Date} | sort | uniq -c | sort -nr > RANK/ip-rank-${Date}.txt
sed 's/^ *//' RANK/ip-rank-${Date}.txt | sed 's/ /,/' > CSV/ip-rank-${Date}.csv
# IP アドレスの名前解決
sed 's/ */ /' RANK/ip-rank-${Date}.txt | cut -d ' ' -f 3 > TEMP/only-ip-address-${Date}.txt
while read Ip_Address
do
dig -x ${Ip_Address} >> RANK/fqdn-${Date}-1.txt
done < TEMP/only-ip-address-${Date}.txt
cat RANK/fqdn-${Date}-1.txt | grep PTR | grep -v ';' > RANK/fqdn-${Date}-2.txt
expand RANK/fqdn-${Date}-2.txt | sed -r 's/\s+/ /g' | cut -d ' ' -f 5 > RANK/fqdn-${Date}-3.txt
# 人気ページランキング
cut -d ' ' -f 7 access_log-${Date} | sort | uniq -c | sort -nr > RANK/page-rank-${Date}.txt
sed 's/^ *//' RANK/page-rank-${Date}.txt | sed 's/ /,/' > CSV/page-rank-${Date}.csv
# 時刻毎のアクセス数ランキング
cut -d ' ' -f 4 access_log-${Date} | cut -d ':' -f 2 | uniq -c | sort -nr +2 -3 > RANK/page-access-hourly-${Date}.txt
sed 's/^ *//' RANK/page-access-hourly-${Date}.txt | sed 's/ /,/' > CSV/page-access-hourly-${Date}.csv
# Device & iOS
cut -d ' ' -f 13,14 access_log-${Date} | sort | uniq -c | sort -nr > RANK/device-and-ios_ver-${Date}.txt
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment