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 ...
- 02-03-2009 #1Just 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.
- 02-03-2009 #2Just 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.
- 02-06-2009 #3Linux 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 ' :' _
- 02-06-2009 #4
Make your own date format:
date "+%Y%M%d-%H%m%S"
try "man date" for more date codes.
- 02-06-2009 #5Just Joined!
- Join Date
- Sep 2006
- Posts
- 14
Thanks for the suggestions guys!


Reply With Quote