Member-only story

How To Easy Work With Apache logs with uniq/awk

Maciej
2 min readJan 18, 2021

--

Introduction

I will show you how to easily search Apache web server logs.

Environment

  • Vagrant + Ubuntu 18.04
  • Apache 2.4

Let’s Start

In each example we focus on Apache raw log and one-liner pattern files which will be parsed.

  • Number of accesses by request.

Examples:

root@vagrant:/var/log/apache2# grep 09/Dec/2020:19 access.log | awk -F '"' '{print $2}' | awk '{print $2}' | sort | uniq -c | sort -n -r
36 /
1 /icons/ubuntu-logo.png
1 /favicon.ico
  • Number of requests by hour, daily, hourly, separated, second

Examples:

#daily
root@vagrant:/var/log/apache2# grep 'Dec/2020' /var/log/apache2/access.log | awk '{print $4}' | cut -b 2-12 | sort | uniq -c
39 09/Dec/2020
#hourly
root@vagrant:/var/log/apache2# grep '09/Dec/2020' /var/log/apache2/access.log | awk '{print $4}' | cut -b 2-15 | sort | uniq -c
39 09/Dec/2020:19
#separated
root@vagrant:/var/log/apache2# grep '09/Dec/2020:19' /var/log/apache2/access.log | awk '{print $4}' | cut -b 2-18 | sort | uniq -c
3 09/Dec/2020:19:02
35…

--

--

Maciej
Maciej

Written by Maciej

DevOps Consultant. I’m strongly focused on automation, security, and reliability.

No responses yet