views:

173

answers:

3

Hey everyone,

I am running a batch job that has been going for many many hours, and the log file it is generating is increasing in size very fast and I am worried about disk space.

Is there any way through the command line, or otherwise, that I could hollow out that text file (set its contents back to nothing) with the utility still having a handle on the file?

I do not wish to stop the job and am only looking to free up disk space via this file.

Im on Vista, 64 bit.

Thanks for the help,

A: 

Depends on how it is writing the log file. You can not just delete the start of the file, because the file handle has a offset of where to write next. It will still be writing at 100mb into the file even though you just deleted the first 50mb.

You could try renaming the file and hoping it just creates a new one. This is usually how rolling logs work.

shimpossible
Thanks - but it wont allow me to rename the file as it says its being used by another process
barfoon
+1  A: 

Well, it depends on how the job actually works. If it's a good little boy and it pipes it's log info out to stdout or stderr, you could redirect the output to a program that you write, which could then write the contents out to disk and manage the sizes.

If you have access to the job's code, you could essentially tell it to close the file after each write (hopefully it's an append) operation, and then you would have a timeslice in which you could actually wipe the file.

If you don't have either one, it's going to be a bit tough. If someone has an open handle to the file, there's not much you can do, IMO, without asking the developer of the application to find you a better solution, or just plain clearing out disk space.

Dave Markle
A: 

You can use a rolling log class, which will wrap the regular file class but silently seek back to the beginning of the file when the file reaches a maximum designated size.

It is a very simple wrap, either write it yourself or try finding an implementation online.

Danra