Solved

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

Posted on 2007-04-05
5
25,937 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:
Christopher McKay 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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…

821 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