Apacheのエラーログを集約する
なんかエラーログって同じメッセージが何回も出力されるので、何種類出てるのかパッと見よく分からない。
なんで、集約するワンライナー書いた。忘れないうちにメモ。
これが元のログファイル。
[root@CentOS httpd]# cat error_log* [Tue Jun 14 21:35:40 2011] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [Tue Jun 14 21:35:40 2011] [notice] Digest: generating secret for digest authentication ... [Tue Jun 14 21:35:40 2011] [notice] Digest: done [Tue Jun 14 21:35:40 2011] [notice] Apache/2.2.3 (CentOS) configured -- resuming normal operations [Tue Jun 14 21:50:52 2011] [error] [client 127.0.0.1] Directory index forbidden by Options directive: /var/www/html/ [Tue Jun 14 21:58:36 2011] [error] [client 192.168.137.1] Directory index forbidden by Options directive: /var/www/html/ [Tue Jun 14 21:58:37 2011] [error] [client 192.168.137.1] File does not exist: /var/www/html/favicon.ico [Tue Jun 14 21:58:37 2011] [error] [client 192.168.137.1] File does not exist: /var/www/html/favicon.ico [Tue Jun 14 21:58:37 2011] [error] [client 192.168.137.1] File does not exist: /var/www/html/favicon.ico [Tue Jun 14 21:59:09 2011] [notice] caught SIGTERM, shutting down [Tue Jun 14 21:59:19 2011] [notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) [Tue Jun 14 21:59:19 2011] [notice] Digest: generating secret for digest authentication ... [Tue Jun 14 21:59:19 2011] [notice] Digest: done [Tue Jun 14 21:59:19 2011] [notice] Apache/2.2.3 (CentOS) configured -- resuming normal operations [Tue Jun 14 21:59:22 2011] [error] [client 192.168.137.1] Directory index forbidden by Options directive: /var/www/html/ [Tue Jun 14 22:18:06 2011] [error] [client 192.168.137.1] Directory index forbidden by Options directive: /var/www/html/ [Wed Jun 15 21:06:15 2011] [notice] caught SIGTERM, shutting down
これが出力結果。
[root@CentOS httpd]# cat error_log* | sed -e "s/\[.\+\] //" | sort | uniq -c | sort 2 Apache/2.2.3 (CentOS) configured -- resuming normal operations 2 Digest: done 2 Digest: generating secret for digest authentication ... 2 caught SIGTERM, shutting down 2 suEXEC mechanism enabled (wrapper: /usr/sbin/suexec) 3 File does not exist: /var/www/html/favicon.ico 4 Directory index forbidden by Options directive: /var/www/html/
“error_log”で始まるファイルをコンカチして、ブラケットで囲まれてるところを削除して、昇順にソートして、集計しつつ重複行を削除して、件数順にソート。