linux 網站日誌分析常用命令

來源:互聯網
上載者:User

1.進入存放日誌的檔案夾

cd d:/111

2.查看該檔案下所有文檔

ls

3.合并日誌或其他檔案

cat *.log > example.log #合并尾碼為log的記錄檔

cat 1.log 2.log > 3.log #合并指定的日誌

4.提取百度蜘蛛(如果有錯誤,請參考:http://www.lirang.net/post/38.html)

grep "Baiduspider" example.log > baiduspider.txt #提取404、500等其他以此類推

5.同時提取符合兩個屬性的東西

egrep "Baiduspider|Googlebot" example.log > spider.txt #其他以此類推

6.提取百度蛛蛛訪問產生的所有狀態代碼和數量,並按降序排列

cat *.log |grep ‘Baiduspider’ | awk '{print $11}' |sort|uniq -c|sort -nr|awk '{print $2 "\t" $1}' >baiduma.log

或:awk '{print $11}'  baidu.log |sort|uniq -c|sort -nr |awk '{print $2 "\t" $1}' >baiduma.log

7.提取百度蜘蛛訪問碼為200的前100個頁面及訪問次數,並按降序排列

cat *.log |grep 'Baiduspider' | grep  ' 200 ' |awk '{print $5}' | sort | uniq -c | sort -nr | head -n 100 >baiduurl200.log

或:grep  ' 200 ' baidu.log  | awk '{print $5}' | sort | uniq -c | sort -nr | head -n 100 >baidu200.log

8.提取所有404、301、302等非正常狀態代碼的頁面並按降序排列

awk '($11 ~/404/)'   baidu.log | awk '{print $11,$5}' | sort >baidu404.log

9.計算蜘蛛抓取的不重複URL個數

cat access.log |grep Baiduspider+ |awk '{print $7}'|sort -u|wc

匯出:cat access.log |grep Baiduspider+ |awk '{print $7}'|sort -u  >baiduspiderurl.txt

給每個URL加上抓取的次數:cat access.log |grep Baiduspider+ |awk '{print $7}'|sort |uniq -c >baiduspiderurl.txt

10.截取百度蜘蛛訪問的來源IP、時間、抓取的URL、返回碼和抓取的大小

grep "Baiduspider+" example.log |awk '{print $1 "\t" $4 "\t" $7 "\t" $8 "\t" $9 "\t" $10}' >Baiduspider.txt

11.上邊命令中的$是根據這裡自訂,自己對照自己的日誌

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.