Solved

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

Posted on 2007-04-05
5
25,497 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
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…
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 fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

743 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

13 Experts available now in Live!

Get 1:1 Help Now