PDA

View Full Version : Log Rotation Help


Ghetto_Man
1st February, 2004, 08:47 AM
I am from the Linux world and I need help with a Windows issue. I need to set my start script so that it keeps server logs when the server crashes and restarts. Right now I have it copying server.log to servercrash.log which is fine. But if the server crashes twice before I catch it I miss the first crash. How can I make it to where the logs number themselves like servercrash.log servercrash1.log, etc or perhaps have a date associated with the file name like servercrash-mar012003.log or something. Help on this would be appreciated.

DeadMeat
2nd February, 2004, 04:02 PM
Quick and dirty way is to add code like this to the batch file running UT. (This saves the 10 previous logs)

[code:1:896ab613b2]
if exists server.log.9 del server.log.9
if exists server.log.8 rename server..log.8 server.log.9
if exists server.log.7 rename server.log.7 server.log.8
if exists server.log.6 rename server.log.6 server.log.7
if exists server.log.5 rename server.log.5 server.log.6
if exists server.log.4 rename server.log.4 server.log.5
if exists server.log.3 rename server.log.3 server.log.4
if exists server.log.2 rename server.log.2 server.log.3
if exists server.log.1 rename server.log.1 server.log.2
if exists server.log rename server.log server.log.1
[/code:1:896ab613b2]

There are some tricks that let you get the date and rename the log to a date extension but I can't remember them right now and this leads to a lot of log bloat with old logs needing to be manually deleted.

GL HF
|LCN|DeadMeat
--
Logs are an admin's best friend, learn to use them. Hint: Find or grep can filter logs for needed info quickly.

Ghetto_Man
3rd February, 2004, 02:53 AM
Thanks DeadMeat

Ghetto_Man
3rd February, 2004, 02:55 AM
Um... I was needing this for a Windows server. I think the info you gave is for linux instead. :-) Correct me if I'm wrong.