2

Currently I keep 6 weeks of apache access_log. If I generate a access summary at month end:

cat /var/log/httpd/access_log* | goaccess --output-format=csv

the summary will include some access data from previous month.

How can I skip logs of previous month and summarise from first day of month?

p.s. the data-format is: %d/%b/%Y

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
ohho
  • 50,879
  • 75
  • 256
  • 383

1 Answers1

1

You can trade the Useless Use of cat for a useful grep.

grep -n $(date +'[0-3][0-9]/%b/%Y') /var/log/httpd/access_log* |
goaccess --output-format=csv

If the logs are by date, it would be a lot more economical to skip the logs which you know are too old or too new, i.e. modify the wildcard argument so you only match the files you really want (or run something like find -mtime -30 to at least narrow the set to a few files).

(The cat is useless because, if goaccess is at all correctly written, it should be able to handle

goaccess --output-format=csv /var/log/httpd/access_log*

just fine.)

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • `grep --no-filename $(date +"[0-3][1-9]/%b/%Y")` (the `--no-filename` is needed for goaccess) – ohho Oct 29 '14 at 09:37
  • @ohho Duh, I tried to remind myself but forgot anyway! Thanks for the note -- updated. – tripleee Oct 29 '14 at 09:55
  • From the man page, this should work too: `zcat -f access.log* | sed -n '/'\`date +"01\/%b\/%Y"\`'/,$ p' | goaccess --output-format=csv` – Kayla Oct 29 '14 at 16:35
  • @Kayla This works poorly if `access.log.0.Z` is the newest -- this is a situation where the wildcard expansion will produce the files in completely the wrong order. – tripleee Oct 29 '14 at 16:37
  • BTW, should `[0-3][1-9]` be `[0-3][0-9]`? – ohho Oct 30 '14 at 01:20