Log Rolling Help

January 13, 2010 at 14:21:12
Specs: Windows 2003
Hello,

I am trying to clear the contents of a log file app1.log which is being used by a server.
I am using windows 2003.

Following are the commands I tried so far.

command: echo on>app1.log
output: The process cannot access the file because it is being used by another process

command:type nul>app1.log
output: The process cannot access the file because it is being used by another process

command:type app1.log>NUL>app1.log
output: The process cannot access the file because it is being used by another process

I am able to open the file, select content,delete and save the file under same name - manually.
Can some one Please suggest how to put this in a batch script.

Thank You.


See More: Log Rolling Help

Report •


#1
January 13, 2010 at 16:06:00
not sure, is win2003 equiv. to winME?
maybe try:
echo on>fil
xcopy /r /y fil app1.log


if you can do it manually, you should be able to do it from batch, otherwise, when you did it manually via notepad or edit, it should have given the same error of access denied.
also not clear if the app1.log is on "your" (local) machine or if you're trying to delete it from server. it might be a file-privelage issue.


Report •

#2
January 14, 2010 at 13:26:38
wow it worked !!
Thanks soo much.

Report •

#3
January 16, 2010 at 04:30:12
You could also use an agressive loop, to try until success. If you use DEL or TYPE (with redirect) or XCOPY, that may not matter a lot if the issue is time related:

:begin
del app1.log
if NOT exist app1.log goto end
echo app1.log still exists... retrying...
goto begin
:end

Note that if the process which is writing to the file, is a very fast one, it may occur that the file gets recreated between the DEL and the IF command.


Report •

Related Solutions


Ask Question