Calling all UNIX gurus...

Discussion in 'Mac Help/Tips' started by cleo, Apr 19, 2003.

  1. cleo macrumors 65816

    cleo

    Joined:
    Jan 21, 2002
    Location:
    Tampa Bay Area, FL, USA
    #1
    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...
     
  2. wheezl macrumors member

    Joined:
    Dec 3, 2002
    #2
    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.
     
  3. zimv20 macrumors 601

    zimv20

    Joined:
    Jul 18, 2002
    Location:
    toronto
    #3
    good one. if apache doesn't guarantee using 10 digits, you can substitute:

    referrer_log.*[0-9]

    for

    referrer_log.??????????
     
  4. wheezl macrumors member

    Joined:
    Dec 3, 2002
    #4

    And it's prettier that way too :)
     
  5. Nipsy macrumors 65816

    Nipsy

    Joined:
    Jan 19, 2002
    #5
    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.
     

Share This Page