Skip to content

Instantly share code, notes, and snippets.

@yonixw
Last active April 29, 2021 20:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yonixw/4b06392bb0742903e7569a3f4378c908 to your computer and use it in GitHub Desktop.
Save yonixw/4b06392bb0742903e7569a3f4378c908 to your computer and use it in GitHub Desktop.
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
Copy link
Author

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