linux日志汇总,Linux日志分析常用命令汇总(示例代码)
1、查看當天有多少個IP訪問:
awk ‘{print $1}‘ log_file|sort|uniq|wc –l
2、查看某一個頁面被訪問的次數:
grep "/index.php" log_file | wc –l
3、查看每一個IP訪問了多少個頁面:
awk ‘{++S[$1]} END {for (a in S) print a,S[a]}‘ log_file
4、將每個IP訪問的頁面數進行從小到大排序:
awk ‘{++S[$1]} END {for (a in S) print S[a],a}‘ log_file | sort –n
5、查看某一個IP訪問了哪些頁面:
grep ^111.111.111.111 log_file| awk ‘{print $1,$7}‘
6、去掉搜索引擎統計當天的頁面:
awk ‘{print $12,$1}‘ log_file | grep ^"Mozilla | awk ‘{print $2}‘ |sort | uniq | wc –l
7、查看2009年6月21日14時這一個小時內有多少IP訪問:
awk ‘{print $4,$1}‘ log_file | grep 21/Jun/2009:14 | awk ‘{print $2}‘| sort | uniq | wc –l
8.查看訪問前十個ip地址
awk ‘{print $1}‘ |sort|uniq -c|sort -nr |head -10 log_file
9.訪問次數最多的文件或頁面
cat log_file |awk ‘{print $11}‘|sort|uniq -c|sort -nr
10.通過子域名訪問次數,依據referer來計算,稍有不準
cat log_file | awk ‘{print $11}‘ | sed -e ‘ s/http:‘ -e ‘ s//.*//‘ | sort | uniq -c | sort -rn | head -20
11.?列出傳輸大小最大的幾個文件
cat log_file |awk ‘($7~/.php/){print $10 " " $1 " " $4 " " $7}‘|sort -nr|head -100
12.???列出輸出大于200000byte(約200kb)的頁面以及對應頁面發生次數
cat log_file |awk ‘($10 > 200000 && $7~/.php/){print $7}‘|sort -n|uniq -c|sort -nr|head -100
13.?如果日志最后一列記錄的是頁面文件傳輸時間,則有列出到客戶端最耗時的頁面
cat log_file |awk ‘($7~/.php/){print $NF " " $1 " " $4 " " $7}‘|sort -nr|head -100
14.???列出最最耗時的頁面(超過60秒的)的以及對應頁面發生次數
cat log_file |awk ‘($NF > 60 && $7~/.php/){print $7}‘|sort -n|uniq -c|sort -nr|head -100
15.?列出傳輸時間超過?30?秒的文件
cat log_file |awk ‘($NF > 30){print $7}‘|sort -n|uniq -c|sort -nr|head -20
16.?列出當前服務器每一進程運行的數量,倒序排
ps -ef | awk -F ‘ ‘ ‘{print $8 " " $9}‘ |sort | uniq -c |sort -nr |head -20
17.?當前WEB服務器中聯接次數最多的ip地址
netstat -ntu |awk ‘{print $5}‘ |sort | uniq -c| sort -nr
18.?查看日志中出現100次以上的IP
cat log_file |cut -d ‘ ‘ -f 1 |sort |uniq -c | awk ‘{if ($1 > 100) print $0}‘|sort -nr |less
19.?查看最近訪問量最高的文件
cat log_file |tail -10000|awk ‘{print $7}‘|sort|uniq -c|sort -nr|less
20.?查看日志中訪問超過100次的頁面
cat log_file | cut -d ‘ ‘ -f 7 | sort |uniq -c | awk ‘{if ($1 > 100) print $0}‘ | less
21.?統計某url,一天的訪問次數
cat log_file | grep ‘12/Aug/2009‘|grep ‘/images/index/e1.gif‘|wc|awk ‘{print $1}‘
22.?前五天的訪問次數最多的網頁
cat log_file | awk ‘{print $7}‘|uniq -c |sort -n -r|head -20
23.?從日志里查看該ip在干嘛
cat log_file | grep 219.239.157.240 | awk ‘{print $1""$7}‘ | sort | uniq -c | sort -nr | less
24.?列出最最耗時的頁面(超過60秒的)
#cat log_file |awk ‘($NF > 60 && $7~/.php/){print $7}‘ |sort -n|uniq -c|sort -nr|head -100
25.?網站一天的點擊量
cat log_file |grep ‘12/Nov/2011‘ | grep "******.jsp"|wc|awk ‘{print $1}‘|uniq
26.?訪問網站的獨立IP有多少
cat log_file |grep ‘12/Aug/2011‘ |grep "******"|wc|awk ‘{print $1}‘|uniq
通過日志查看當天ip連接數,過濾重復
cat log_file | grep "20/Oct/2008" | awk ‘{print $2}‘ | sort | uniq -c | sort –nr
27.?用tcpdump嗅探80端口的訪問看看誰最高
tcpdump -i eth0 -tnn dst port 80 -c 1000 | awk -F"." ‘{print $1"."$2"."$3"."$4}‘ | sort | uniq -c | sort –nr
28.?查看某一時間段的ip連接數
grep "2006:0[7-8]" log_file | awk ‘{print $2}‘ | sort | uniq -c| sort -nr | wc -l
總結
以上是生活随笔為你收集整理的linux日志汇总,Linux日志分析常用命令汇总(示例代码)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何为linux 桌面文件内存,linu
- 下一篇: linux 其他常用命令