[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Batch Job - Call one after another

Posted on 2013-01-01
5
Medium Priority
?
886 Views
Last Modified: 2013-01-04
Hello experts,

I have multiple batch jobs that I need to run in a sequence.  I don't know how long it will take each job to run, so I don't want to set a schedule.

I want to create 1 batch file that is schedule to run at 1am.  Is it possible to set this batch file to execute one batch job and then once complete, to start the other one?

Example:

Call Batch1.bat......
Complete....
Call Batch2.bat........
Complete
Call Batch3.bat
0
Comment
Question by:holemania
[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
5 Comments
 
LVL 57

Assisted Solution

by:Bill Prew
Bill Prew earned 400 total points
ID: 38734845
Yes, and you actually are very close to the mechanics.  If you want to wait for each BAT to complete before the next starts then use CALL, as in this bat file example:

@echo off
call batch1.bat
call batch2.bat
call batch3.bat

~bp
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 1600 total points
ID: 38735131
Just to add... be careful you don't use the command "EXIT" to finish any of the batches otherwise it will stop the main one too.  Use EXIT /B to finish them instead or just let it work its way to the end of the batch file.  If one relies on the other at all you might want to set an error level and check for it, i.e.

@echo off
set error=NO
(call batch1.cmd || set error=Batch1 %errorlevel%
call batch2.cmd || set error=%error%Batch2 %errorlevel%
call batch3.cmd || set error=%error%Batch3 %errorlevel%
) > logfile.txt

if "%error%"=="NO" (
  echo Completed OK
  exit /b 0
) else (
  echo There was at least one error -- %error%
  exit /b 1
)

That would give you a logfile.txt of the output of the other batches and return errorlevel "1" to your scheduler if any of the other three had an error.

Lots of things you can do like emailing etc. but depends what you are scheduling and how important it is!

Steve
0
 
LVL 25

Expert Comment

by:Lionel MM
ID: 38736338
Steve is the master at batch files so if what you suggest works for you great. I deal with this by adding a line at the end of each batch file to start the next. That is to say at the end of batch1.bat and have a line to start batch2.bat, namely
Start batch2.bat; and then in batch2.bat I have the line Start batch3.bat; and then have my exit after the start batchx.bat to close the current one

@echo off
commands
commands
start batch2.bat
exit
0
 

Author Closing Comment

by:holemania
ID: 38744973
Thank you.  That worked wonderfully.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 38745120
No problem... a little over complicating a three line batch but with the benefit of some error checking.

thanks

Steve
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

656 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