Problem with locked log file produced by batch file

  • Thread starter Ragnar Midtskogen
  • Start date
R

Ragnar Midtskogen

Hi,

I have set up backups on all of our servers, running batch files by using
Windows Scheduled Tasks.
I redirect the output from the batch file to a log file.
A couple of times recently I have found that the Scheduled Task ran but the
batch file didn't. The log file was not even opened.
I have no idea what caused the log file to be left in a state like that, but
the last thing the batch file does is to FTP the backup file to another
server, so my guess is that it could be a dropped FTP connection. I have no
error handling for the FTP code.
I finally found that the log file was locked. I tried to delete it but got
the message that the file was in use.
BTW, The ST runs the batch file as the same user as I log on to the server
with (Through Terminal Server client).

Is there a way to free the file, short of rebooting the server?

Any help would be appreciated.

Ragnar
 
M

Matt Williamson

Ragnar Midtskogen said:
Hi,

I have set up backups on all of our servers, running batch files by using
Windows Scheduled Tasks.
I redirect the output from the batch file to a log file.
A couple of times recently I have found that the Scheduled Task ran but
the batch file didn't. The log file was not even opened.
I have no idea what caused the log file to be left in a state like that,
but the last thing the batch file does is to FTP the backup file to
another server, so my guess is that it could be a dropped FTP connection.
I have no error handling for the FTP code.
I finally found that the log file was locked. I tried to delete it but got
the message that the file was in use.
BTW, The ST runs the batch file as the same user as I log on to the server
with (Through Terminal Server client).

Is there a way to free the file, short of rebooting the server?

Any help would be appreciated.

Ragnar
 
M

Matt Williamson

Is there a way to free the file, short of rebooting the server?
eh, sorry. Meant to hit Ctrl+A but my fingers were in the wrong position and
I hit Alt+S, which sent the blank message

The first thing I would do is make sure any instances of CMD.EXE, FTP.EXE or
any other program you're calling are closed and see if the lock on the file
goes away.

If that doesn't do it, I'd use a utility like OH.EXE to try to determine
which process is holding the file open. If nothing shows up I'd just reboot
the server.
 
R

Ragnar Midtskogen

Thank you Matt,

Installed OH.exe and ran it. Unfortunately, the linked list was not enabled,
so I need to reboot. But of course, when I reboot the file will be freed, so
I may never know what process had it open.

Oh well, at least I can find out the next time it happens. That may take a
long time though, in 10 years of running Scheduled Tasks I have never had
this problem.

Ragnar
 
M

Mark V

In microsoft.public.win2000.cmdprompt.admin Ragnar Midtskogen
wrote:
Thank you Matt,

Installed OH.exe and ran it. Unfortunately, the linked list was
not enabled, so I need to reboot. But of course, when I reboot
the file will be freed, so I may never know what process had it
open.

Ypu could try HANDLE.EXE (Sysinternals)
Oh well, at least I can find out the next time it happens. That
may take a long time though, in 10 years of running Scheduled
Tasks I have never had this problem.

You might use tlist, pslist or other process lister in batch to check
for hung processes...possibly using kill, pskill or other to
terminate the program as needed.

If the log file is not closed one still may be able to
TYPE logfile >logfilecopy
in order to subsequently access and manipulate a copy of it.
 
D

dbareis [Windows Installer MVP]

Hi,

My guess for the day is that your previous schedule is still running
(and perhaps you don't auto terminate it if required). "Process
Explorer" might be quite useful to examine the running processes.

Bye,
Dennis
 
R

Ragnar Midtskogen

Thanks Mark,

I will try the listers you mentioned, it would be nice to know what is using
the file.

Ragnar
 
D

dbareis [Windows Installer MVP]

Hi,


Ragnar said:
Thanks Mark,

I will try the listers you mentioned, it would be nice to know what is using
the file.

"Process Explorer" can tell you

Bye,
Dennis
 
J

Jason Gurtz

Google for "unlocker" If this freeware program can't unlock the file
then probably nothing will short of logging off or, at worst, rebooting.

~Jason

--
 
R

Ragnar Midtskogen

Thank you!

Process Explorer did the job. It turned out XCOPY had the file open. The
batch file does call XCOPY so I guess the batch file got terminated while
XCOPY was running.

Process Explorer is really a neat utility.

Ragnar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top