Solved

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

Posted on 2016-09-12
5
42 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
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 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…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

705 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

17 Experts available now in Live!

Get 1:1 Help Now