Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

CMD prompt intermittently hangs after bat file execution

Posted on 2010-11-26
4
Medium Priority
?
937 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 500 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 71

Assisted Solution

by:Qlemo
Qlemo earned 500 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

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
A recent project that involved parsing Tableau Desktop and Server log files to extract reusable user queries for use in other systems. I chose to use PowerShell to gather the data, and SharePoint to present it...
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

636 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