apache日誌分析

  • 列出當天訪問次數最多的IP

cut -d- -f 1 /usr/local/apache2/logs/access_log |uniq -c |sort -rn | head -20

 

cut
       -d, --delimiter=DELIM
             use DELIM instead of TAB for field delimiter
              表示用-分割,然後-f 1
       -f, --fields=LIST
              selectonly these fields;  also print any line that contains  no
             delimiter character, unless the -s option is specified
           表示打印第一部分,就是ip
 uniq 是將重複行去掉, -c表示前面加上數目,
       sort -rn 就是按照數字從大到小排序,
       head -20取前面20

 

  • 查看當天有多少個IP訪問

awk '{print $1}' log_file|sort|uniq|wc –l

 

  • 查看某一個頁面被訪問的次數

grep "/index.php" log_file | wc –l

 

  • 查看每一個IP訪問了多少個頁面:

awk '{++S[$1]} END {for (a in S) print a,S[a]}' log_file

 

  • 將每個IP訪問的頁面數進行從小到大排序:

awk '{++S[$1]} END {for (a in S) print S[a],a}' log_file |sort –n

 

  • 查看某一個IP訪問了哪些頁面:

grep ^111.111.111.111 log_file| awk '{print $1,$7}'

 

  • 查看200962114時這一個小時內有多少IP訪問:

awk '{print $4,$1}' log_file | grep 21/Jun/2009:14 | awk'{print $2}'| sort | uniq | wc -l


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章