Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

cleo

macrumors 65816
Original poster
Jan 21, 2002
1,186
0
Tampa Bay Area, FL, USA
My web host runs Apache. I'm trying to set up a cgi script that basically gives a graphical analysis of my referrer logs. My host names the logs like this:

referrer_log.1050192000.gz
referrer_log.1050364800.gz
referrer_log.1050451200.gz
referrer_log.1050537600.gz
referrer_log.1050624000.gz
referrer_log.1050710400

The suffix is assigned server-wide, not just on my account, which is why the numbers skip around. So anyway, what I want to do is write a cron job to copy the most recent log file to another file called referrer_log. My problem lies in selecting the right file to copy. How do I tell the server to select only the most recent log, and only if it's not already gzip'd?

Any help would be greatly appreciated...
 
Hmm, the question is a bit vague. a really ugly way to do this from the command line that should work is:

cp `ls -ut1 referrer_log.?????????? | head -n 1` referrer_log

What you should actually do is find your favorite scripting language and write a nice logic block that does exactly what you described in your post.
 
Originally posted by wheezl

cp `ls -ut1 referrer_log.?????????? | head -n 1` referrer_log

good one. if apache doesn't guarantee using 10 digits, you can substitute:

referrer_log.*[0-9]

for

referrer_log.??????????
 
good one. if apache doesn't guarantee using 10 digits, you can substitute:

referrer_log.*[0-9]

for

referrer_log.??????????


And it's prettier that way too :)
 
There are many freely available analysis tools which you can set up as a cron job to scan your log directory daily, and create html output.

Most of these also handle .gz logs regardless of naming convention by scanning the folder in question.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.