In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use shell to calculate the total amount of downloads of each ip in access.log files. The article is very detailed and has a certain reference value. Interested friends must finish reading it!
Working environment: Red Hat Enterprise Linux Server release 6.5 (Santiago), bash
#! / bin/bash
#
# cat xferlog | awk'{print $7J 8}'| sort-n | head-100 > ssh.txt
Cat xferlog | awk'{print $7 charge 8}'| sort-t. -k3pr 4-n > ssh.txt
Ip= (`cat ssh.txt | cut-d ""-f1`)
Dx= (`cat ssh.txt | cut-d ""-f2`)
Sum=0
For i in `seq 0 $((${# ip [@]}-1)) `
Do
# determine whether the read size is 0
If [${dx [$I]}! = 0]; then
Z1 = `echo "${dx [$I]} / 1024" | bc`
Sum=$ (($z1+$sum))
Fi
# judge whether it is in the end
If [$I! = ${# ip [@]}]; then
# determine whether the value is the second to last, and if so, compare it with the last one
If [$I = = $((${# ip [@]}-2))]; then
# if it is not equal, the value of the penultimate value and the last value are equal, then a sum is output
If [${ip [$((${# ip [@]}-1))]}! = ${ip [$((${# ip [@]}-2))]}]; then
[$num-ge 1024] & & echo "${ip [$I]}-$(($sum/1024)) M"
[${dx [$((${# dx [@]}-1))]}-ge 1024] & & echo "${ip [$(($item1))]}-$((${dx [$((${# dx [@]-1))]} / 1024)) M"
Exit 1
Else
Sum=$ (($sum+$ {dx [$((${# dx [@]}-1))]})
[$sum-ge 1024] & & echo "${ip [$I]}-$(($sum/1024)) M"
Exit 2
Fi
Else
# if you don't get to the second, make a normal comparison, and the latter one is compared with the current one
If [${ip [$(($iTun1))]}! = ${ip [$I]}]; then
[$sum-ge 1024] & & echo "${ip [$I]}-$(($sum/1024)) M"
Sum=0
Fi
Fi
Fi
Done
The above is all the contents of the article "how to use shell to calculate the total number of downloads per ip in access.log files". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.