Solved

Xcopy - from server share to multiple IP's using batch file (not working)

Posted on 2016-09-12
5
64 Views
Last Modified: 2016-09-12
hi guys,

I'm using a script created by OdBA, which I then modified based on the help I got here. I am merely trying to copy the files from a server share on a domain to multiples of PC's on the same domain.

Here is the script. In the location C:\Temp\machines.txt is where I put the IP address of the computer(s). I've only put one IP in there for now. The script runs, but nothing is copied.

@echo off
setlocal enabledelayedexpansion
set MachineFile=C:\Temp\machines.txt
set LogFile=C:\Temp\machines.csv
>"%LogFile%" echo "Machine","State","Errorlevel"
for /f %%a in ('type "%MachineFile%"') do (
      echo Processing %%a ...
      ping.exe -4 -n 2 %%~a | find /i "TTL" >NUL
      if errorlevel 1 (
            >>"%LogFile%" echo "%%~a","Offline","n/a"
      ) else (
            ECHO xcopy \\server\share\filename \\%%~a\c$\temp /e
            >> "%LogFile%" echo "%%~a", "online", "!ErrorLevel!"
)
)
echo Done.

Any ideas guys?

Thanks a lot
Yashy
0
Comment
Question by:Yashy
  • 3
  • 2
5 Comments
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 41794002
The script is in test mode and will only echo the xcopy command it would normally run. Remove the uppercase ECHO in line 12 to run it for real.
@echo off
setlocal enabledelayedexpansion
set MachineFile=C:\Temp\machines.txt
set LogFile=C:\Temp\machines.csv
>"%LogFile%" echo "Machine","State","Errorlevel"
for /f %%a in ('type "%MachineFile%"') do (
	echo Processing %%a ...
	ping.exe -4 -n 2 %%~a | find /i "TTL" >NUL
	if errorlevel 1 (
		>>"%LogFile%" echo "%%~a","Offline","n/a"
	) else (
		ECHO xcopy "\\server\share\filename" "\\%%~a\c$\temp" /e
		>> "%LogFile%" echo "%%~a", "online", "!ErrorLevel!"
	)
)
echo Done.

Open in new window

If you post scrips, please enclose them in "Style Code" tags (see the tool bar above the Comment field).
0
 
LVL 1

Author Comment

by:Yashy
ID: 41794029
Aah...sir OdBA:).

I did take out the ECHO, but then when I run the batch file, the actions is constantly looping and it doesn't copy the file. So the command prompt is merely running the xcopy and says 'Processing' with a load of writing and then reruns the same thing over and over without doing anything.
0
 
LVL 83

Expert Comment

by:oBdA
ID: 41794034
You didn't name the batch file xcopy.cmd or xcopy.bat? If so, rename it to something that is not a native Windows command.
0
 
LVL 1

Author Comment

by:Yashy
ID: 41794040
I've renamed it and it does the same thing sadly.
0
 
LVL 1

Author Comment

by:Yashy
ID: 41794041
Ignore!!!

I've got it working. It may have been folder permissions stopping it. All good matey. Thank you:))
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Recently, an awarded photographer, Selina De Maeyer (http://www.selinademaeyer.com/), completed a photo shoot of a beautiful event (http://www.sintjacobantwerpen.be/verslag-en-fotoreportage-van-de-sacramentsprocessie-door-antwerpen#thumbnails) in An…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

770 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