How would you do this on Windows? (Truncating runaway log file)

Joined
Dec 29, 2000
Messages
2,470
I had a process start bugging out and dumping crap tons of log entries, 2MB/sec. I restarted the processes, but it seemed to freak out randomly, and I couldn't really pinpoint the cause.
I upgraded the software to a newer version and it ran for 90 minutes just fine, where earlier it would freak out within a few minutes. I think I'm in the clear.

So I want to go to bed... but the question is... how do I bang something together to nuke the log files if they get >100MB?

In Linux I would just do
Code:
while true;do for i in `find /log/directory/ -type f -name 'log_file' -size +100000K`;do date;:>$i;done;sleep 15;done
on a VNC session and leave it until the morning.

Are there any native tools to do something like that on Windows (without Cygwin/GNU Utils)?
on Server 2K3, 2K8
 
powershell is what I would use

the following code is using shorthand, remove the -verbose from ri if you do not want output when the file is deleted.
Code:
while ($true) { gci c:\some\dir -recurse -Include mylogfile.log | ? { $_.length -gt 100mb } | ri -verbose; sleep 15 }
 
Last edited:
So what you are saying, once it goes over 100mb start deleting things from the top of the file so the file goes back down to 100mb?

edit: nm i think you just want to clear the text file but not delete it. This might be possible but i think only though accessing .net directly i will have to research.
 
Last edited:
Ok there is a built in command. Clear-Content

Code:
while ($true) { gci c:\some\dir -recurse -Include mylogfile.log | ? { $_.length -gt 100mb } | Clear-Content; sleep 15 }
 
Back
Top