Shell intercept Log Statistics link count log ip

Source: Internet
Author: User
Tags ip number


Get logs by time period

Sed-n '/22\/dec\/2015:00/,/22\/dec\/2015:50/p ' localhost_access_log.2015-11-10.txt >/tmp/acc.www.log sed-n '/22\ /dec\/2015:00/,/22\/dec\/2015:50/p ' localhost_access_log.2015-11-10.txt |head-3 sed-n '/22\/Dec\/2015:00/,/22\/Dec \/2015:50/p ' localhost_access_log.2015-11-10.txt |tail-3 ======================================awk '/22\/Dec\/ 2015:00/,/22\/dec\/2015:09/{print $} ' access_www.log >/tmp/acc.www.log awk '/22\/dec\/2015:00/,/22\/dec\/ 2015:09/{print $} ' access_www.log |head-3 awk '/22\/dec\/2015:00/,/22\/dec\/2015:09/{print $} ' access_www.log |tail- 3============================================================================




#######################################################

Statistics Link Number:

Netstat-tan | awk '/^tcp/{++state[$NF]}end{for (s in state) {print S "============" State[s]}} ' Netstat-tan|awk '/^tcp/{s[$6]++} END {fo R (n in S) {print n "============" S[n]}} '------------------------[[email protected] ~]# Netstat-a|awk '/tcp/{s[$6]++} EN D {for (n in S) {print n "============" S[n]}} ' time_wait============292established============13syn_recv============ 2last_ack============3listen============5[[email protected] ~]# # Netstat-tn | awk '/^tcp/{lens=split ($5,client, ":"); ip[client[1]]++}end{for (i in IP) print I,ip[i]} '





#######################################################

Count the number of connections per IP:

Netstat-ntu | Awk-f ' [:]+ '/^tcp/{print $6} ' |sort |uniq-c |sort-rn|head-5netstat-ntu | awk ' {print $} ' | Cut-d:-F 1 | Sort | uniq-c| Sort-n-R | Head-n 5 | Grep-v 127.0.0.1 "Netstat-ntu | Tail-n +3 | awk ' {print $} ' | Cut-d:-F 1 | Sort | uniq-c | Sort-n-R |head-n 3netstat-ntu | Tail-n +3 | awk ' {print $} ' | Egrep-o "[0-9]{1,3}. [0-9] {1,3}. [0-9] {1,3}. [0-9] {1,3} "| Sort | uniq-c | Sort-n-R





#######################################################

IP number of the statistics log

awk ' {ip[$1]++}end{for (i in IP) {print ip[i], i}} ' Access_www.log |sort-rn-k1 |head-10 [[email protected] nginx]$ awk ' {ip[$1]++}end{for (i in IP) {print ip[i], i}} ' Access_www.log |sort-rn-k1 |head-106792 140.206.49.1786106 66.249.69. 2474734 115.159.29.1912501 42.121.119.2292444 114.119.8.922179 10.162.85.261741 10.51.0.2091710 121.37.61.2201580 121.41.37.721568 66.249.75.95[[email protected] nginx]$


This article is from the "Struggle Bar" blog, please be sure to keep this source http://lvnian.blog.51cto.com/7155281/1727079

Shell intercept Log Statistics link count log IP

Related Article

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.