Solved

Copy file script

Posted on 2011-02-15
13
957 Views
Last Modified: 2012-05-11
I need to create to scripts iin a classroom. Both scripts are essentially the same. I need to copy a config file from 1 pc to a location on 20 other pc's. I just wanted to know if I have to copy from source to destination for each pc or if I can have 1 copy from source to multiple destinations. Any ideas would be great.
0
Comment
Question by:j8547
  • 5
  • 4
  • 2
  • +2
13 Comments
 
LVL 83

Expert Comment

by:oBdA
ID: 34899657
There are several possibilities to run this in a more or less simple script for all machine.
Easiest one: create a file with the names of the 20 "other" PCs (one name per line), for example MachineFile.txt.
Then run something like this in a command prompt in the directory with the list:
for /f "delims=" %a in ('type "MachineList.txt"') do copy "C:\Source\file.txt" "\\%a\C$\Target\Location

If you want to save this as a batch script, double up on the percebt signs:
for /f "delims=" %%a in ('type "MachineList.txt"') do copy "C:\Source\file.txt" "\\%%a\C$\Target\Location

There are other possibilities as well. Do the "other" PCs have a consistent, numeric, naming convention (pc01, pc02, ..., pc20)?
0
 
LVL 19

Expert Comment

by:Thommy
ID: 34899658
You have to call copy for each destination pc by UNC names with hostnames or ips...

copy config.txt \\pc01\c$\configDir\config.txt
...
copy config.txt \\pc20\c$\configDir\config.txt


You can also use ip address:

copy config.txt \\192.168.65.1\c$\configDir\config.txt
...
copy config.txt \\192.168.65.20\c$\configDir\config.txt


0
 

Author Comment

by:j8547
ID: 34899696
I can't use IP address but the pc names range from ...b1 to ...b20

I will try themn out now
0
 
LVL 83

Expert Comment

by:oBdA
ID: 34899747
With these names, you don't even need a machine list. Just use
for /L %i in (1, 1, 20) do copy "C:\Source\file.txt" "\\...b%i\C$\Target\Location
0
 

Author Comment

by:j8547
ID: 34900014
I am getting the system cannot find the path specified yet the paths look correct. Any ideas???
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 34900080
The closing quotes in the target folder are missing, that could be the issue.
Otherwise, please copy and paste the output of
for /L %i in (1, 1, 20) do @ECHO copy "C:\Source\file.txt" "\\...b%i\C$\Target\Location"
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 82

Expert Comment

by:leakim971
ID: 34900166
You may create a share folder in the main server, create a file with the twenty computer names and use psexec : http://technet.microsoft.com/en-us/sysinternals/bb896649
to run a copy from all the computer to get the file(s) from the main server.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 34900201
0
 
LVL 3

Expert Comment

by:symmcom
ID: 34900235
Assuming you are the administrator and trying to copy the file from the Server to your 20 client computers, simplest form would be:
1. Create a Batch file (anyname.bat)
2. Inside the Batch file type - copy SourceDrive\Thefile.xyz \\ClientPCName\c$\Folder
3. Copy paste this command 19 other times and change the ClientPCName to correct name

This should copy the file to all destination.
0
 

Author Comment

by:j8547
ID: 34901285
It was the quotes. Thanks it is working perfectly now.
0
 

Author Comment

by:j8547
ID: 34901292
Sorry also does the person have to be an admin or can this script use an admin account?????
0
 
LVL 83

Expert Comment

by:oBdA
ID: 34901415
Currently, it has to be an admin due to the administrative share.
If you want this to be run by a regular user, it's safest to share the target folder (with Full Access share permissions for Everyone), and give the "copy" user Change permissions on the target folder.
0
 

Author Comment

by:j8547
ID: 34901422
Thanks
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article will give core knowledge of JavaScript and will head in to your first JavaScript program. I am Durvesh Naik and I am here to deal with this series of JavaScript. I will teach you JavaScript in part wise , as its quite boring to read big…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

706 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

15 Experts available now in Live!

Get 1:1 Help Now