Solved

CMD prompt intermittently hangs after bat file execution

Posted on 2010-11-26
4
929 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 85

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 70

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

707 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