one log file for several batch processes locks up - batch-file

I have very basic batch file knowledge. My first script was something I found to export Oracle Discoverer reports via windows task scheduler. That's basically all I know, I've got several of them (maybe 40 or so) that run at various times, some every 30 mins. They sometimes overlap in time.
My issue is not the specific discoverer export, but the logging of errors. I want to log everything to a single log file... with excel and access processes, I can loop until free and all is good; with the discoverer batch files, the log file gets locked at the beginning and doesn't let anything else log in until done. Some of these discoverer reports may take 30 mins or more, messing up all my runs.
Here's an example of my bat file:
#echo off
echo my process %date% %time% >>c:\test.log
c:\orant\DISCVR4\DIS4USR.EXE /connect MyUserID/MyPassword#myserver /open "c:\DiscoReport.DIS" /export xls "c:\MyFile.xls" /batch 1>>c:\test.log 2>>&1
I have a bat file with several of those individual process bat files, so that they run one at a time. That works fine. But when the run takes longer than estimated, then the next run fails... because they all start by running disco, and the log file is locked throughout and until the end... Is there something I can do to just open and close it right at the time of adding the results only?
I've looked for answers, and I believe there's something that might be done with the TEE or redirecting the results maybe to null and then using that as input piped to write to the log? but I don't really know how to do this... looked, tried, weeks and weeks, can't get anything working... Pretty please, I'm sure those who know, can do this with one single line.. Pls help...

Essentially, NO - if you want the log file to contain all events in time-order.
You could have the discoverer processes create their individual logfiles and then
type discoverer.log.file >>logfile
del discoverer.log.file
which would group all of the discoverer process output together in the logfile.
Otherwise, you'd have to put up with more than one log.
I severely doubt TEE could do it as TEE would then itself need to hold the log open, so you're back at the start - But I'll emphasise I haven't tried it.

Related

Log File getting locked by Batch

I wrote a relativly big batch script (multiple calls, all together ~150 lines) and have noticed an issue with a log file being created by said script. I'm only using the log file with the echo command like echo this is a test >>test.log, there are no other procceses writing or reading the file. Most of the time it works perfectly fine but just about one out of 20 times the script fails because the log file is locked. What could possibly cause this?
EDIT:
I went through old logs I had and i think I can safely say that the error always occurs after this command fciv.exe !currentPath! -r -wp -xml %~dp0sourcehash.xml >>%~dp0Server.log
So this might actually be a problem with fciv.exe...

Connect Direct Multiple files, one Node.

I'm working on a project that requires sending multiple files to the same node. The files are available for sending at the same time and I created a simple C.D shell script to send the files. I looped the call to this script to send all the files (about 20) at the same time.
In my script I'm intending to delete the files within the loop and after the CD script is called. However,.. some one at work , a colleague, told me that the files may not be sent on the spot but rather put in a queue for transmission at a later stage if the C.D node is busy and hence deleting the files would cause errors.
Can someone advise if this is the case? Are the files not fiscally copied even if put in a queue?
I find it weird that the CD script would complete with a successful return code and give me the process number and I still cannot delete the file?
Thanks,
Sergio
You can use the if statement for each file, if the exit code for the file is 0, only the file is deleted and CD moves to the next step for copying the next file.
if (step01=0) then
run task (Do something)
sysopts="rm filename"

How to make a file to run with Task Manager to close a program at a certain time each day?

I seek a simple script/batch file to close a program at a certain time. Someone recently gave me a single line of text that I put into a notepad and had Task Manager run this file at a certain time and that worked. But I had to format that hard drive and lost the file.
So my goal is to run a batch file that will kill a process at a set time each day. Let's call the program flubber.exe. I'm not a programmer and the research I've done on tskill has only confused me. I know it was a simple short command but I am unable to remember it. Help.....
Thank you to all who respond.
Majikwiz
taskkill /im flubber.exe /t
This will terminate all running processes with executable name flubber.exe.

Ensuring application close in batch files

Specifically, I'm using DGIndex in a batch file as part of a sequence to do some video encoding.
Despite accepting CLI params, DGIndex pops up a window to do the processing. This then disappears when it's finished, but the command line hangs as though it's still open. The process is no longer running.
Is there something built-in that I can do to ensure it doesn't hang, or is there a third-party proxy utility that will monitor for a process end then close itself?
I had the same problem with DGIndex in batch files. I know this is an old question, but it seems DGIndex hasn't been updated since then, so this might still be relevant.
DGIndex has 2 different command-line "styles", in the manual one being called legacy (the one using upper case letters for the settings), the other UNIX-style (lower case letters).
For me, the "-exit" command of the UNIX-style command-line did not work, so that the batch file did not receive a corresponding message from DGIndex, even though it finished its job correctly. I used the legacy commands instead, and the problem was gone.
"Funny" that Dan had the problem with the legacy commands, so the other way round.
Regards, Mike.
You could use something like this:
#echo off
echo Running program
start dgindex -BF=[vob.txt] -FO=0 -IA=2 -OM=2 -TN=0 -OF=[out] -HIDE -EXIT
ping 127.0.0.1 -n 10
taskkill /im dgindex.exe /f
exit >nul
This batch file basically runs the DGIndex program and then pauses for 10 seconds before attempting to close the program. Just replace the 10 with a delay of your choice, something long enough that if the program is still running it means it's crashed, then it will be closed after the delay.
I'm pretty sure you can't tell if the program has hung or not (at least not in batch anyways). This at least makes sure it isn't running if you need to run it again if it did crash.
Hope this helps!
If you use start, the batch file should return immediately after starting the dgindex application.
You can pass the /WAIT flag to start to it to tell it to wait until the process has exited before moving to the next line of the batch file.
start /WAIT dgindex -BF=[vob.txt] -FO=0 -IA=2 -OM=2 -TN=0 -OF=[out] -HIDE -EXIT
I know this is old, but did you ever get it figured out?

Bat file MOVE fails due to other process handle

I have a bat file as part of larger maintenance system that runs on a nightly basis, performs a bit of housekeeping, SVN updating etc. Part of this involves moving/deleting files, however, occasionally this fails due to another process not releasing a handle on the files/dirs to be moved. Is there any way to force the BAT file to override any existing handles and continue with the MOVE? I can only think of a look up method using ProcessExplorer/Assassin - although I'm not sure that would even work. Alternatively a "sleep" and then reattempt if it failed the first time, although that would be a matter of luck than solving the underlying problem. Any ideas/suggestions much appreciated. Thanks.
Robocopy has a move function, and can wait on error
Here are a few things that I have done in similar situations:
Before the move command, ensure that other script threads CD out of the target directory.
Use robocopy (from the Resource Kits) with options like retry /r:3 and wait /w:5.
Script the first action as COPY so the script can continue working, then later in the script do the deletion at the old/unneeded location.
As you've already mentioned, create a little retry loop using IF ERRORLEVEL commands to test the success of the MOVE command.

Resources