Find the answer to your Linux question:
Results 1 to 5 of 5
Hey guys, I am having a difficult time with rotating logs on my game server. I just want it to rotate a log, but I want it to make the ...
  1. #1
    Just Joined!
    Join Date
    Sep 2006
    Posts
    14

    Bash script log rotate

    Hey guys,

    I am having a difficult time with rotating logs on my game server.

    I just want it to rotate a log, but I want it to make the new log with the date in the name. This is the command I am using.

    cp log.log log.1.log

    What I want it to do is

    cp log.log log.[date].log

    So that it it wont just over write the log.1.log file each time it has to rotate.

  2. #2
    Just Joined!
    Join Date
    Sep 2006
    Posts
    14
    I think I got it.

    I delcared the DATE at the top of the script like so;

    DATE=`date | sed -e 's/ /_/g' -e 's/\:/_/g'`

    Then added it as part of the log name, like so;

    cp gsconsole.log ${DATE}.log

    Now it seems to create a new log file each time the server crashes, the is based upon the time it crashed, so the logs will never be lost.

  3. #3
    Linux User
    Join Date
    May 2008
    Location
    NYC, moved from KS & MO
    Posts
    251
    As an alternative way to get the date string, you can use command tr to simplify things a bit
    date | tr ' :' _

  4. #4
    Just Joined! AdmiralBeotch's Avatar
    Join Date
    Feb 2009
    Location
    Las Vegas, NV
    Posts
    17
    Make your own date format:

    date "+%Y%M%d-%H%m%S"

    try "man date" for more date codes.

  5. #5
    Just Joined!
    Join Date
    Sep 2006
    Posts
    14
    Thanks for the suggestions guys!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...