Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

We have an IIS server on a Windows Server 2003 box where the log files keep filling up the hard disk. What I am looking for is a scheduled process that every once in a while will go in and clean up the logs, deleting anything older then a month. Does something like this already exist or is there a simple script out there I can use and setup as a scheduled task?

share|improve this question
1  
You can configure IIS to use a different location for log files, they don't have to be on the system disk. –  Richard Oct 12 '10 at 10:21
add comment

1 Answer

up vote 1 down vote accepted

Nothing like this is built into Windows, not at least Win2k3 or earlier. You can find dozens of scripts, in your language of choice, to accomplish this. I would use something like a BAT script that called forfiles.exe for anything over 30 days, and have it be scheduled to run daily using Scheduled Tasks.

Also, if your log files are on the system volume, move them to a different volume so when they fill the disk, they don't take the server down.

share|improve this answer
    
Thanks, I found/modified the following bat file using forfiles to delete log files older then 7 days. Forfiles -p D:\IISLogFiles -s -m *.log -d -7 -c "Cmd /C DEL @File" >> file.log 2>&1 –  Peter Oct 12 '10 at 13:49
    
That will do it; I do the same thing on my laptop for clearing out PuTTY logs. Don't forget to mark the answer :-) –  mfinni Oct 12 '10 at 14:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.