5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

apache-ログ分析ワンライナー

Posted at

最近よく使ってるやつ

一応ログフォーマットはデフォルト用。
環境に応じてawkの引数を変えることで独自フォーマットなどにも対応可能(な、はず)。

# アクセス元 IP の一覧
$ cat /var/log/httpd/access_log | cut -d ” ” -f 1 | sort | uniq

# ユーザエージェントの一覧
$ cat /var/log/httpd/access_log | awk -F ‘”‘ ‘{ print $6 }’ | sort | uniq

# リファラ別
$ cat /var/log/apache/access.log|awk '{print $11}'|sort|uniq -c|sort -n

# ブラウザ毎のアクセス数
$ for UA in MSIE Firefox Chrome; do COUNT=`grep$UA” /var/log/httpd/access_log | wc -l`; echo$UA : $COUNT; done

# 特定ファイルへのアクセス数を抽出
$ cat /var/log/httpd/access.log | grep favicon.ico | wc -l

awkを使ったログの時間範囲指定
時間フォーマットはシスログならシスログ、apacheならapacheの時間フォーマットを指定できる。

$ cat file | awk -F - '"開始時間" < $1 && $1 <= "終了時間"'

grepのバッファを無くしてリアルタイムでtail -f

$ tail -f file | grep --line-buffered "word"
5
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?