Skip to content

Instantly share code, notes, and snippets.

@yonixw
Last active Apr 29, 2021
Embed
What would you like to do?
Get nginx users per day
cat nginx_logs.txt // (docker logs with timestamps, so first col ($1) is time)
| tr -cd '\11\12\15\40-\176' // filter non ascii from bot requests
| grep "/202" // get rows with time like Apr/2021 or Jul/2020
| grep 'qp.png' // get rows which will called once per real user
| awk '{split($5,a,":"); print a[1] "\t" $2}' // print time of day and ip
| uniq -c
| sort -rn
| awk '{arr[$2]+=1} END {for (i in arr) {print substr(i,2),arr[i]}}' // Group IPs per day
@yonixw

This comment has been minimized.

Copy link
Owner Author

@yonixw yonixw commented Apr 29, 2021

awk '{arr[$2]+=$1} for adding same ip more than once, or awk '{arr[$2]+=1} (add 1) per ip in the same day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment