Ever log into a UNIX-like system and need to find what’s happening with Apache or lighttpd? Sure, on a server you’ve set up you can use apache-top or mod_status, but on a server needing attention NOW and one you’ve never logged into what can you do? Well, I wrote a simple one-liner to help.
This is one ugly one-liner. It’s also useful on an unfamiliar server (UNIX-y) to find popular virtual hosts and scripts without knowing too much about the implementation details of Apache or lighttpd for that server. To try it log into a system running Apache or lighttpd with superuser privileges (due to the netstat -ltpn and lsof dependencies) and then Copy/Paste on the command line.
Here’s output on a dev machine with almost no traffic (a busy server is much more interesting):
-------/var/log/apache2/this-access.log------02.Nov.2009: 1 02 03.10 - 03.19 00K 1 02 04.00 - 04.09 00K 1 02 08.40 - 08.49 00K 103 02 11.00 - 11.09 26K 1 02 11.30 - 11.39 00K 1 02 15.40 - 15.49 00K 1 02 16.30 - 16.39 00K 1 02 17.20 - 17.29 00K -------/var/log/apache2/other_vhosts_access.log------02.Nov.2009: -------/var/www/sites/other.otr/logs/ins.pect.me-access.log------02.Nov.2009:
The output line shows the number of hits, day of the month, time in 10 min increments and kilobytes of transfer. If an IP had triggered the limits for TOPFILES or TOPIPS there would be a list of those IPs and popular request targets by number of occurrences for the given timeframe.
