Apacheのログからアクセス元IPをユニークに抽出するワンライナーシェルの応用で、アクセス数をカンマ区切りcsv出力するシェルです。
uniq_ip_count.sh
1 2 |
#!/bin/sh ACCESSLOG=[access_log]; IPLIST=`cat access_log_20100105 | awk '{print $1}' | sort | uniq` && for TARGET in $IPLIST; do COUNT=`grep $TARGET access_log_20100105 | wc -l`; echo $TARGET,$COUNT; done; |
※すべて半角で入力していますが、WordPressが勝手に全角文字にしてしまう場合がありますので、注意してください。
※[access_log]を該当のアクセスログファイル名に変更してください。
出力といっても、echoするだけなので、
1 |
$ ./uniq_up_count.sh > result.csv |
のように実行してください。
No comments yet. You should be kind and add one!
By submitting a comment you grant typista a perpetual license to reproduce your words and name/web site in attribution. Inappropriate and irrelevant comments will be removed at an admin’s discretion. Your email is used for verification purposes only, it will never be shared.