How to use shell to calculate the total amount of downloads for each ip of access.log files
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!