GrepFilter: How to pull the last 10 authusers from an Apache log file, without all the noise?
This is why I flunked out of compsci.
I made a little extranet web thingie for my world-scattered family to use to stay in touch and so on. It works great, technically, but of course it's a pain always nagging everyone to use it. So I'd like to use the power of passive-aggressive love, by just showing the last time each user has logged in on the home page. Then my family can all guilt each other into being more regular.
Everyone's an htaccess user, so the info is right there in the apache logs. But I'm out of my depth here. I'm looking for a quickie grep/shellscript/perl way to pull the last ten unique authusers (htusers) from a standard apache logfile, with dates.
My regular old apache log looks like this:
in.log
====
74.53.68.133 - no1son [01/Nov/2007:01:13:15 -0400] "GET /page.htm HTTP/1.1" 200 - "referrer stuff"
74.53.68.133 - no1son [01/Nov/2007:01:13:31 -0400] "GET /page1.htm HTTP/1.1" 200 - "referrer stuff"
64.13.232.151 - no2son [02/Nov/2007:12:13:01 -0400] "GET /page.htm HTTP/1.1" 200 - "referrer stuff"
68.178.232.99 - no2son [02/Nov/2007:12:13:11 -0400] "GET /page3.htm HTTP/1.1" 200 - "referrer stuff"
68.178.232.99 - no2son [02/Nov/2007:12:13:22 -0400] "GET /page.htm HTTP/1.1" 200 - "referrer stuff"
74.53.68.130 - no1son [03/Nov/2007:14:13:36 -0400] "GET /page.htm HTTP/1.1" 200 - "referrer stuff"
74.53.68.130 - no1son [03/Nov/2007:14:13:37 -0400] "GET /page4.htm HTTP/1.1" 200 - "referrer stuff"
68.178.232.99 - no3son [04/Nov/2007:03:13:32 -0400] "GET /page9.htm HTTP/1.1" 200 - "referrer stuff"
68.178.232.99 - no3son [04/Nov/2007:03:13:35 -0400] "GET /page3.htm HTTP/1.1" 200 - "referrer stuff"
64.13.232.151 - no2son [04/Nov/2007:09:13:36 -0400] "GET /page.htm HTTP/1.1" 200 - "referrer stuff"
And I want to turn that into this (just a text file) on demand:
out.txt
=====
Most Recent Logins By:
-----
no1son 03/Nov/2007 14:13:37
no2son 04/Nov/2007 09:13:36
no3son 04/Nov/2007 03:13:35
no4son never
So I'd like a shell script or something (perl?) that I can invoke when I feel like it, or from a cron job, or something. Notice that number four son, he never logs in at all. I need to cover that, maybe by calling the script with a list of uids I'm looking for?
But my perl is poor, and my grep skills worse. I can get the last lines from each user out, I think, but then I hit the wall of ripping apart the "fields" usefully and the wall of trying to grep (?) out stuff with square brackets and dashes... and those walls HURT my poor little head.
Can someone show me a simple way to do this? If the big parts work, I can muddle my way through refining it. But a couple hours of Google has just left me feeling inadequate, like a bad son. :(
cat foo.log | awk '{print $3}' |grep -v - |tail -n 10
posted by roue at 8:30 AM on November 4, 2007