[FreeBSD 5.2.1] Giving dynamic filenames

Discussion in 'Linux & BSD' started by Glaanieboy, Sep 26, 2004.

  1. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
    I want to create a script (along with a daily/weekly cronjob), that does the following to the httpd (apache) logs:
    • Rename the logs
    • Create a new, empty log file by using touch <filename>
    • Move the backup file to a directory, for example a dir in my own home dir
    This is basically it, but I have a problem/question about the first part: As you probably have read, I want to use this script with a daily/weekly cronjob, so I get the apache logs sorted daily/weekly. In order to tell them apart, I want to add a dynamic extension to the filename, like httpd-access.log.2004-9-26, or httpd-access.log.2004-<weeknumber>, but how can I create a dynamic filename like that? Can I do that in the script? How?

    Btw, I created a part of the script, which is like:
    Code:
    cd /var/log/httpd
    ;**This is where I want the dynamic extension. In this example
    ;**I used .bck at the end of the filename,
    ;**but I want this to be dynamic.
    mv httpd-access.log /path/to/archive/httpd-access.log.bck && touch httpd-access.log
    mv httpd-error.log /path/to/archive/httpd-error.log.bck && touch httpd-error.log
    Thanks :)
     
  2. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
    Consider this thread obselete, I was just browsing the internet about totally unrelated matters and I found it:
    :eek:

    Close this please.

    Btw, I promise I'll try to search longer before I ask my question here...
     
  3. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    I think you can set that up in the httpd.conf file as well
     
  4. Glaanieboy

    Glaanieboy Moderator

    Messages:
    2,626
    Location:
    The Netherlands
    Hmm, maybe I'll do that later. Anyway, I have a cronjob running at every monday 0:01 hours, using the script I just created, so that's ok too.
     
  5. vern

    vern Dominus Political User Folding Team

    Messages:
    1,571
    Location:
    Minnesota, USA
    I'm not a BSD person ... but wouldn't logrotate pretty much do the same thing?
     
  6. j79zlr

    j79zlr Glaanies script monkey Political User

    Messages:
    2,725
    Location:
    Chicago
  7. X-Istence

    X-Istence * Political User

    Messages:
    6,498
    Location:
    USA
    Sure.