Solved

Can a batch script file run multiple commands at the same time?

Posted on 2007-04-05
5
25,610 Views
Last Modified: 2008-11-17
I've got a dos batch file that is scheduled to run every night to copy/backup files from different workstations at different branches to my server across different VPN links.

Right now, the batch file runs one line after the other.  Is there any way to have run multiple lines at the same time???  I want to copy files from multiple branches at the same time.  But I only want one item in the task scheduler.

Sample of current batch file

Robocopy \\branch1\sharename c:\backup\branch1 /e
Robocopy \\branch2\sharename c:\backup\branch2 /e
Robocopy \\branch3\sharename c:\backup\branch3 /e


Because the available download bandwidth at the main office is so much greater than the available upload bandwidth at the remote branches, I can run all three copies at the same time, and get the job done in 1/3 the time.

I know I could schedule each of the three, but with so many scheduled tasks in there already I would like to tell the batch file to run all three at the same time.

Is it possible?

Thanks!
0
Comment
Question by:brasslan
5 Comments
 
LVL 22

Accepted Solution

by:
Bartender_1 earned 100 total points
ID: 18859438
Use the start command before the robocopy command

start Robocopy \\branch1\sharename c:\backup\branch1 /e
start Robocopy \\branch2\sharename c:\backup\branch2 /e
start Robocopy \\branch3\sharename c:\backup\branch3 /e

This will launch the command and return to the batch file right away to continue running additional commands.

Hope this helps!

:o)

Bartender_1
0
 
LVL 17

Assisted Solution

by:RDAdams
RDAdams earned 85 total points
ID: 18859455
http://www.aumha.org/a/batches.php

Other good info options with the start command
0
 
LVL 67

Assisted Solution

by:sirbounty
sirbounty earned 65 total points
ID: 18859489
Agree that Bartender_1 has solved this one - I would just compact your script using:

For %%a in (branch1 branch2 branch3) do start Robocopy \\%%a\sharename c:\backup\%%a /e
0
 
LVL 95

Expert Comment

by:Lee W, MVP
ID: 18861468
Also agree bartender_1 has provided the solution, but to add, I consider it a best practice to get in the habbit of using quotes when using command line copying... helps prevent errors if and when you have a space in the specified path.  So to further expand on sirbounty's idea:

For %%a in (branch1 branch2 branch3) do start Robocopy "\\%%a\sharename" "c:\backup\%%a" /e
0
 
LVL 6

Author Comment

by:brasslan
ID: 18869539
I think I'm done getting comments on this one, so time to close it out.  I almost accepted a solution right after bartender's first response, but I'm glad I didn't.  The link that Adams gave me was awesome for including other batch commands and options!  Sir Bounty really had a good idea for compacting, now my batch file is much smaller, but more important, when I change the robocopy switches I only have to do it on 4 lines instead of on 40 lines!  Lee had a good idea, but to be honest, I already have the quotes because my source and destination already have spaces in them :-) (just couldn't see it in the sample!)

Thanks guys!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
Learn the basics of modules and packages in Python. Every Python file is a module, ending in the suffix: .py: Modules are a collection of functions and variables.: Packages are a collection of modules.: Module functions and variables are accessed us…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

910 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

20 Experts available now in Live!

Get 1:1 Help Now