Linux practical log analysis script and linux Log Analysis script

Source: Internet
Author: User

Linux practical log analysis script and linux Log Analysis script

Log Analysis

Randomly tail an access_log file. Below is a classic access record

218.19.140.242--[10/Dec/2010: 09: 31: 17 + 0800] "GET/query/trendxml/district/todayreturn/month/2009-12-14/2010-12-09/haizhu_tianhe.xml HTTP/1.1" 200 1933 "-" "Mozilla/ 5.0 (Windows; u; Windows NT 5.1; zh-CN; rv: 1.9.2.8) Gecko/20100722 Firefox/3.6.8 (. net clr 3.5.30729 )"

Practical log analysis script
After learning about the definitions of logs, I will share some log analysis scripts posted on the Internet.

1. view the number of apache Processes
Ps-aux | grep httpd | wc-l

2. Analyze the log to view the number of ip connections on the current day
Cat default-access_log | grep "10/Dec/2010" | awk '{print $2}' | sort | uniq-c | sort-nr

3. view the url accessed by the specified ip address on the current day.
Cat default-access_log | grep "10/Dec/2010" | grep "218.19.140.242" | awk '{print $7}' | sort | uniq-c | sort-nr

4. view the top 10 URLs on the current day
Cat default-access_log | grep "10/Dec/2010" | awk '{print $7}' | sort | uniq-c | sort-nr | head-n 10

5. See what the specified ip Address does.
Cat default-access_log | grep 218.19.140.242 | awk '{print $1 "\ t" $8}' | sort | uniq-c | sort-nr | less

6. view the most frequently accessed minutes (find the hotspot)
Awk '{print $4}' default-access_log | cut-c 14-18 | sort | uniq-c | sort-nr | head

7. count the number of characters contained in a text

Cat pic. access. log | grep/2012/| wc-l

Cat c_access.log | grep "/message/publishmsg/\ |/message/publish/"> test1.log

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.