I want to know how many unique IPs have connected to my site. The following worked until logs started rotating:
cut -d' ' -f1 /var/log/apache2/access.log | uniq -d | wc -l Is grepping through all the logs the idiomatic solution?
zgrep is the tool to read rotated logs. It is installed by default on Ubuntu, Mint and Arch.
#!/usr/bin/env bash # Count unique IPs. zgrep -E [0-9]*\.[0-9]*\.[0-9]*\.[0-9] /var/log/apache2/access.log* | cut -d':' -f2 | cut -d' ' -f1 | uniq -d | wc -l Yes, grep can take multiple files, but so can cut. Since you've already done it that way and it works, then you won't have to change anything other than put a glob in there that can catch all the log files that you need. Something like...
cut -d' ' -f1 /var/log/apache2/access*.log | uniq -d | wc -l