Solved

CMD prompt intermittently hangs after bat file execution

Posted on 2010-11-26
4
911 Views
Last Modified: 2012-05-10
Hi All

Here in the office we have a bat file which runs every 5 minutes. This bat file ftp's to a remote location, grabs a couple of files and then inputs the contents of those files into a database.

We are having a problem lately whereby the CMD prompt which the bat file opens does not close. It just hangs there on the screen blank. As a result of that the scheduled task which is supposed to run every 5 mins does not run.

This doesnt happen every time but does happen frequently which means I get phone calls/emails wondering whats going on.

What I want to find out is how to makle sure that if the prompt hangs on the screen I have some way of killing it automatically. Whether that is some other sort of scheduled task that searches for it and kills it if it sees it or what I dont know,

All suggestions are apreciated and a rough copy of the bat file is below

@echo off 
echo Starting Import > Import.log 
FTP -s:ftp.txt >> Import.log 
ren *.csv *.process
for /f %%a in ('dir /b *.process') do sqlldr userid=username@database log=loader.log data="%%a" control=loader.ctl 
sqlplus -s username@database@runbatchsql.sql >> Import.log  
ren *.process *.complete
del /Q *.complete
echo Import Complete >> Import.log
EXIT

Open in new window

0
Comment
Question by:darran_d
4 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 250 total points
ID: 34217343
Your batch file is not reentrant. If an execution takes more than 5 minutes, a second process will start working in the same folder on the same files that the first process is still working on. This can cause all kinds of trouble.
I'd recommend to NOT schedule this to run every 5 minutes.
Instead, schedule it to run once, and let it loop infinitely (or set an end time with the scheduler), with a pause of 5 minutes or less inbetween loops.
In case you don't have it yet, sleep.exe is part of the W2k3 Resource Kit Tools, http://www.microsoft.com/downloads/en/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&displaylang=en.

@echo off 
echo %Date% %Time% Starting Import >Import.log
:Loop
echo %Date% %Time% Continuing Import >>Import.log
FTP -s:ftp.txt >>Import.log
ren *.csv *.process
for /f %%a in ('dir /b *.process') do sqlldr userid=username@database log=loader.log data="%%a" control=loader.ctl 
sqlplus -s username@database@runbatchsql.sql >>Import.log  
ren *.process *.complete
del /Q *.complete
echo %Date% %Time% Import Complete >>Import.log
sleep 300
goto :Loop

Open in new window

0
 
LVL 68

Assisted Solution

by:Qlemo
Qlemo earned 250 total points
ID: 34217387
The batch file does not need to be reentrant, as the scheduler will not try to run the task again as long as it is hanging. But if you provide a time for how long the batch is allowed to run in the task, the batch will be killed. The risk of that is that data might get imported repeatedly, if the SQL*Loader executed successful on at least one .process file, but the remainder did not work. It would be better to include the rename into the FOR loop - load one file, rename it, next file.
0
 

Author Closing Comment

by:darran_d
ID: 34391524
The problem seems to have resolved itself for some reason but all comments were technically correct so I am splitting the points among all respons
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
In this previous article (https://oddytee.wordpress.com/2016/05/05/provision-new-office-365-user-and-mailbox-from-exchange-hybrid-via-powershell/), we made basic license assignments to users in O365. When I say basic, the method is the simplest way …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now