Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Batch file FOR loop to rotate and rename log files?

Status
Not open for further replies.

hgate73

IS-IT--Management
Feb 22, 2008
80
0
0
US
Hi there,

I'm trying to archive and rotate some log files from a profile deletion script.

The batch file creates a file "OCPN2_master.log" from the script. This is what I currently have but it's kind of ugly:

Code:
:: Log file rotation section. Archives up to 6 backups, ("backup" through "backup5) and deletes backup6 if it exists
IF EXIST Logs\OCPN2_master.log.backup6 del Logs\OCPN2_master.log.backup6
IF EXIST Logs\OCPN2_master.log.backup5 rename Logs\OCPN2_master.log.backup5 OCPN2_master.log.backup6
IF EXIST Logs\OCPN2_master.log.backup4 rename Logs\OCPN2_master.log.backup4 OCPN2_master.log.backup5
IF EXIST Logs\OCPN2_master.log.backup3 rename Logs\OCPN2_master.log.backup3 OCPN2_master.log.backup4
IF EXIST Logs\OCPN2_master.log.backup2 rename Logs\OCPN2_master.log.backup2 OCPN2_master.log.backup3
IF EXIST Logs\OCPN2_master.log.backup rename Logs\OCPN2_master.log.backup OCPN2_master.log.backup2
IF EXIST Logs\OCPN2_master.log rename Logs\OCPN2_master.log OCPN2_master.log.backup

I'd like to be able to archive indefinitely, or only keep the oldest 3 log files with a rotating number (i.e. 1 becomes 2, 2 becomes 3, 3 becomes 1 again). Is this possible?

I was previously posting under "GeneralDzur" but hgate73 is my new username.
 
Let me preface this by saying I am not a vbscript person but I would post this in the vbscript forum because I think that would be a better solution for what your trying to do. Then just schedule it to run daily.

Hope this helps
 
Hey Paladin, thanks for the reply. I would post it over there, but this is a batch file, not vbscript

I was previously posting under "GeneralDzur" but hgate73 is my new username.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top