Solved

CMD prompt intermittently hangs after bat file execution

Posted on 2010-11-26
4
915 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 69

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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Synchronize a new Active Directory domain with an existing Office 365 tenant
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

778 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